The worker respects the splines now

This commit is contained in:
2025-12-05 15:49:06 +01:00
parent 82b1a1e78c
commit c96be39e64
4 changed files with 314 additions and 59 deletions

View File

@@ -19,11 +19,11 @@ public class WorkerBeltApproachingBehaviour : AppleState
private void OnEnable()
{
Transform anchorB = transform.Find("AnchorA");
if (anchorB != null)
// ensure roaming ref exists before accessing
Transform anchorA = transform.Find("AnchorA");
if (anchorA != null && workerBeltRoamingRef != null)
{
anchorB.position = workerBeltRoamingRef.midRoamPosition;
anchorA.position = workerBeltRoamingRef.midRoamPosition;
}
Debug.Log("Entered Worker Belt Approaching State");
@@ -50,6 +50,9 @@ public class WorkerBeltApproachingBehaviour : AppleState
private void OnDisable()
{
Debug.Log("Exited Worker Belt Approaching State");
// stop active tween to avoid it running while disabled
aproachTween?.Stop();
aproachTween = null;
}
// callback implementations
@@ -63,15 +66,24 @@ public class WorkerBeltApproachingBehaviour : AppleState
Debug.Log("Approach tween finished");
// cleanup
aproachTween?.Stop();
workerAnimator.SetBool("isLifting?", true);
workerBeltStateMAchineRef.ChangeState(2);
aproachTween = null;
if (workerAnimator != null)
workerAnimator.SetBool("isLifting?", true);
if (workerBeltStateMAchineRef != null)
workerBeltStateMAchineRef.ChangeState(2);
}
public void Update()
{
if (ApproachingSpline.GetDirection(aproachTween.Percentage).x > 0.1)
workerAnimator.SetBool("walkingRight?", true);
if (ApproachingSpline == null || aproachTween == null)
return;
// defensively clamp percentage
float pct = Mathf.Clamp01(aproachTween.Percentage);
Vector3 dir = ApproachingSpline.GetDirection(pct);
if (dir.x > 0.1f)
workerAnimator?.SetBool("walkingRight?", true);
else
workerAnimator.SetBool("walkingRight?", false);
workerAnimator?.SetBool("walkingRight?", false);
}
}