Fast Forwarding causing seeker to miss target and wobble

Hello,

I am using Time.timeScale to set the speed of the game. When user wants to speed up simulation, I set timescale to 2, for example. This causes some issues with seekers that were otherwise working fine at normal speed.

  1. Seekers seem to “wobble” on the way to their target, although they do still head there.
  2. Seekers miss their target and do circles around it until the game is slowed back down. I realize a solution to this might be to just increase the seeker’s end reach distance, but then it would stop too far from it’s intended target.

Is there something I need to do A* side as well, when increasing game speed?

Hi

I suspect this happens because your ‘pick next waypoint distance’ field is set very low.
If it is very low then the agent will try to move to a point very close to it and may end up overshooting that point if the timescale is too high.

1 Like

Thanks for the reply. Your suggestion fixes the pathing nicely when increasing timespeed! I am still having an issue, however, with the seeker circling the final target when the game is sped up. I have tried fixing this in a similar way by increasing ‘end reached distance’, but then I get a new problem where the seeker is choosing to walk on the far right side of the allowed area to it’s next target, after a recent turn, instead of walking in a straight line to its target.

Picture a car going down the road in the middle of its lane, and the lane is perhaps 1.5x its width. Lets say it is following waypoints set in the center of its lane, so it stays in the center of its lane, and not in the far right. It then makes a right turn into a rest area, for example. After it gets out, it goes to the first waypoint back in the middle of the lane, and on the to the next waypoint down the road also in the middle of the lane, as before.

Problem I am seeing now (with increased end reached distance), is that when the game is not sped up, car leaving rest stop goes to the first waypoint in the middle of its lane, then immediately goes to the far right of its lane, on the way to the next waypoint far down the road. It seems to be trying to go directly from its waypoint at the rest stop, to the 2nd waypoint down the road, instead of plotting a straight line from the first ‘exit waypoint’ in the middle of the lane, after the rest stop.

Hi

One way to combat this, albeit at a cost to performance is to simply simulate it twice per frame.
This is possible in the current beta (i.e 4.1+). You can simply do something like this:

// Make the AI not do any movement by itself
ai.canMove = false;
// Run the movement code multiple times per frame
int timeMultiplier = Mathf.Round(Time.timeScale);
for (int i = 0; i < timeMultiplier; i++) {
    Vector3 nextPosition;
    Quaternion nextRotation;
    ai.MovementUpdate(Time.deltaTime / timeMultiplier, out nextPosition, out nextRotation);
    ai.FinalizeMovement(nextPosition, nextRotation);
}
1 Like

Hello,
I finally had time to circle back to work on this bug. Tried the code above, but got an error saying that MovementUpdate does not take 3 arguments. Do I pretty much have to upgrade to the beta version to get this fixed?

Thanks

Hi

Sorry for the late reply.
Yes the MovementUpdate method as I use it in the code snippet above only exists in the beta version.

Hi,

Thanks for the reply and confirmation. I have gone ahead and upgraded again, now that I know how to use the new velocity variable.

I am having a a little trouble understanding where exactly to use the above code though. I noticed that in the MecanimBridge.cs example, it was used within the OnAnimatorMove class.

What if I have no animator though? In my current situation, the wobbliness is happening with a bus object, that doesn’t have any animation. So I just get the waypoints that it needs to go through, and use:

seeker.StartPath(transform.position, nextWaypoint);

When the callback (OnTargetReached) comes that the move is finished, I give it the next waypoint to go to.

In this context, where is the best place to put the above code? Should I override update as I do with human objects that have animation?

Hi

The code snippet will make the AI not do any movement calculations on its own, so that code will step in to do it.
You could for example place it in the update method of a new script that you attach to the same object:

IAstarAI ai;
public void Awake () {
	ai = GetComponent<IAstarAI>();
}

public void Update () {
	// Make the AI not do any movement by itself
	ai.canMove = false;
	// Run the movement code multiple times per frame
	int timeMultiplier = Mathf.Round(Time.timeScale);
	for (int i = 0; i < timeMultiplier; i++) {
		Vector3 nextPosition;
		Quaternion nextRotation;
		ai.MovementUpdate(Time.deltaTime / timeMultiplier, out nextPosition, out nextRotation);
		ai.FinalizeMovement(nextPosition, nextRotation);
	}
}
1 Like

OMG, its working great so far! Thank you for the quick reply :heart:

No more wobbling on the way to target, or circling around the final destination. This just made my day.

Awesome :slight_smile:
I’m glad it works!