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

@@ -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;
}
}