More realistic magnets and a little bit of waiting time

This commit is contained in:
nothke
2024-08-17 16:39:05 +02:00
parent 41ed2e559f
commit fae1548cf4
2 changed files with 21 additions and 5 deletions

View File

@@ -17,12 +17,13 @@ public class Magnet : MonoBehaviour
{
Vector3 dir = otherRb.position - transform.position;
float dirSq = Vector3.SqrMagnitude(dir);
float force = strength * (1.0f / dirSq);
float forceMagnitude = strength * (1.0f / dirSq);
Vector3 force = dir.normalized * forceMagnitude;
otherRb.AddForce(-dir * force);
otherRb.AddForce(-force);
if (rb)
rb.AddForce(dir * force);
rb.AddForce(force);
}
}
}