How to move things at a constant time rate

Hi,

I need to move a box from one position to another at a fixed interval, for example, every 1/10th of a second I want it to move instantly to a new position to the right until it hits a screen boundary and then returns. No tweening, no physics, just change the position immediately.

What’s the correct approach to achieve this. Is it to track delta time in an Update (but this could shoot me over or under 1/10th of a second), or to do a yield with a wait? I need to change the speed over time as the game progresses so cant fix the framerate of the game I don’t think.

Any advice appreciated.

i

Thanks, so fixedUpdate is called at a fixed interval…so deltaTime will be the same each time it is called? I don’t want to overshoot.

i.e. if I am expecting 1/10th of a second, and my variable which starts at 0.1 gets delta time subtracted - it could overshoot slightly to a negative number?

FixedUpdate is for physics; you can use InvokeRepeating.

–Eric

great thanks, how do you uninvoke the repeat?

CancelInvoke

–Eric

Awesome, thanks