Why does this error happen?

I do understand the issue, but it should not happen as the formation makes equal displacement each frame.
consider this:

frame 9:
Enemy formation in bounds. position is still towards right.
frame 10:
Enemy formation steps out of bounds, the direction is then changed to left in this frame.
frame 11;
Enemy formation steps back in the bounds( same position as frame 9), the direction should not be changed in this frame now.

Here’s it visually

I know that splitting the direction flipping (LEFT+RIGHT) check into separate left and right direction setting checks does solve the issue, but the combined check should be working fine mathematically, but doesn’t. could it be due to rounding of float data type ?

1 Like

Nice observation, but the thing is that the displacement isnt always equal, this might be happening because we are multiplying the speed by time.deltatime (which is the time since the last frame), and the time between frames is very likely to be different, but it is hard to know if this is what is causing this problem. A option would be to change the void Update to void FixedUpdate instead, which isnt frame dependent and take out the time.deltatime too, and if it solves this problem even without adding the solution suggested in the classes, then this was Indeed what was causing the problem.


Oh yea, deltaTime not being equal explains it perfectly. Your’s is a nicer observation.
Thanks man.

1 Like

Privacy & Terms