- Home /
Double reference to waypoints in FSM
Hello everybody,
I have a state machine for the avatar to go through state loop: patrol - reachPoint I want to be able to reference in reachPoint, the same point from the previous state. right now what it does is get's a point in a patrol state, but when in reachPoint state it references the next point. here's the code:
int nextWayPoint
public void Patrol()
{
shopper.animator.SetBool("Walk", true);
shopper.navMeshAgent.destination = SceneIndex.instance.waypoints[nextWayPoint].position;
Debug.Log("going to point :" + SceneIndex.instance.waypoints[nextWayPoint].name); //here I get point x
shopper.navMeshAgent.Resume();
}
Next:
int nextWayPoint
public void Reach()
{
if (_delayRoutine != null)
{
shopper.StopCoroutine(_delayRoutine);
_delayRoutine = null;
}
shopper.animator.SetBool("Walk", false);
shopper.transform.forward = SceneIndex.instance.waypoints[nextWayPoint].forward;
Debug.Log("turning to point :" + SceneIndex.instance.waypoints[nextWayPoint].name); //here I get point x+1
playAnimation = true;
PickupItem();
What value can I pass instead of the int nextWayPoint, so it will reference the point it already stands at?
Yes, but how and at what state?
Right now I'm referencing the destination from the patrol state, inside the reachPoint state: shopper.transform.LookAt(shopper.nav$$anonymous$$eshAgent.destination);
but it makes the avatar "jump" back and forward....
EDIT: Quick note, of course nav$$anonymous$$eshAgent.destination is a vector 3 without any rotation information. So I do need to reference the transform of the point
Where does your 'int nextwaypoint' come from? are the methods in 2 different scripts or in one?