Working magnet and crane AI

This commit is contained in:
nothke
2024-08-17 16:13:26 +02:00
parent 601c99ebf6
commit b2d8ac944c
14 changed files with 1764 additions and 3176 deletions

View File

@@ -13,14 +13,16 @@ public class Magnet : MonoBehaviour
{
var otherRb = other.attachedRigidbody;
if(otherRb)
if (otherRb)
{
Vector3 dir = otherRb.position - rb.position;
Vector3 dir = otherRb.position - transform.position;
float dirSq = Vector3.SqrMagnitude(dir);
float force = strength * (1.0f / dirSq);
otherRb.AddForce(-dir * force);
rb.AddForce(dir * force);
if (rb)
rb.AddForce(dir * force);
}
}
}