mirror of
https://github.com/nothke/quality-control.git
synced 2024-12-22 07:47:30 +00:00
More realistic magnets and a little bit of waiting time
This commit is contained in:
parent
41ed2e559f
commit
fae1548cf4
@ -16,12 +16,15 @@ public class CranePickDrop : MonoBehaviour
|
||||
{
|
||||
Idle,
|
||||
Catching,
|
||||
WaitingToCatch,
|
||||
Tansporting,
|
||||
Finished,
|
||||
}
|
||||
|
||||
public State state;
|
||||
|
||||
float timer = 0;
|
||||
|
||||
public void OnTriggerEnterSignalReceived(EnterTriggerSender sender)
|
||||
{
|
||||
var otherRb = sender.triggeredCollider.attachedRigidbody;
|
||||
@ -29,6 +32,7 @@ public class CranePickDrop : MonoBehaviour
|
||||
if (otherRb && otherRb.isKinematic == false && state == State.Idle)
|
||||
{
|
||||
handlingBody = otherRb;
|
||||
crane.testTgt = handlingBody.transform;
|
||||
state = State.Catching;
|
||||
}
|
||||
}
|
||||
@ -51,11 +55,22 @@ public class CranePickDrop : MonoBehaviour
|
||||
|
||||
magnet.strength = magnetStrength;
|
||||
|
||||
crane.testTgt = handlingBody.transform;
|
||||
if (magnet.IsCloseTo(handlingBody, 2f))
|
||||
{
|
||||
crane.testTgt = dropTarget;
|
||||
crane.testTgt = null;
|
||||
|
||||
state = State.WaitingToCatch;
|
||||
timer = 3;
|
||||
}
|
||||
}
|
||||
else if (state == State.WaitingToCatch)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer < 0)
|
||||
{
|
||||
state = State.Tansporting;
|
||||
crane.testTgt = dropTarget;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user