Ending fast forwarding of game causes seeker to go off path, and then return to it

Hello,

This issue is similar to this other issue, in the sense that it is related to fast forwarding of the game by changing timescale.

In this case, however, the problem happens if you stop the fast forwarding when the seeker is taking a turn. What I see happening, is that the seeker doesn’t quite make the turn and slows down somewhere off path (even if it is on a non traverseable area), and then turns around and heads back to continue on the original path at normal speed. What’s weird is that the seeker moves along the path perfectly if I stay on fast forward or normal speed through the turn.

I currently have this solution you suggested, in an update function of a class that extends AIPath. This update function runs base.Update() before running the solution. Is this correct? My theory is that right when I change the game speed, it is perhaps not running an extra movement calculation.

Hi

You are on the right track.
What I think happens is this:

Time.deltaTime is based on the previous frame, so when you stop fast forwarding the time scale will be 1 but the deltaTime will be very large (because last frame was during a fast forward), so it will run a single movement calculation but with a very large delta time. I think the code should be modified to:

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

Works great, thank you! I did not know about unscaledDeltaTime.

1 Like