I am making an agent follow a GKPath by adding to its behavior the goal toFollow: GKPath. Everything works fine, however the agent continues moving in a 8-like shape when reaching the target point on the path. How do I prevent the agent to wander when reaching the target point on a GKPath?
A solution I have thought off would be to set another goal toReachTargetSpeed: 0.0 when close to approaching the target point. However, I am not sure what would be the best practice, since there is no built in way to see when the goal is "completed".
- Do I use an IF statement to check the distance to target at each update:? What about performance?
- Do I use some kind of a GKRule?
Your suggestions would be very much appreciated. Thanks.
I went with the first option, i.e. to track the distance to target in the movementComponent update function:
When the agent is close enough to the target, run the stopMovement function. In turn, this will calculate the time needed to traverse the distance left to target (having a constant speed), and will put a timer as to when to force stop the agent: