Translating Physics Objects

Hello all,

I would like to move physics bodies every frame at a steady velocity. Is just translating the display objects the right way to solve this problem?

displayObject.x =displayObject.x + speed * dt

Will it have any adverse effects on the physics bodies? Because I feel a slight jitter of the bodies in my current implementation.

Thanks

Hi @pselwyn,

I assume you want to adjust for potential frame rate fluctuations by using delta time, which is why you’re aiming for the translate method instead of just setting a linear velocity? If so, have you seen the following tutorial on using delta time? This may help.

https://coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/

Best regards,

Brent

Hi Brent,

Thanks for the reply. I would like to move the physics bodies and I want to know whether translating them manually is a good approach (Will it cause any problems?) or setting its linear velocity is the right way to do it?

Thanks

Hi again,

Either method is fine, but when using physics, I typically recommend that you use all the power that the physics engine gives you. So, in this case, I’d just assign a velocity to the object using “object:setLinearVelocity()”:

http://docs.coronalabs.com/api/type/Body/setLinearVelocity.html

The main reason to consider the delta time thing would be if you wanted the absolute most consistent linear movement rate, even during potential frame rate fluctuations. If you’re not too concerned about that, then using the physics method is fine for most instances.

Have fun,

Brent

That was exactly what I was expecting! Thank you Brent!

Hi @pselwyn,

I assume you want to adjust for potential frame rate fluctuations by using delta time, which is why you’re aiming for the translate method instead of just setting a linear velocity? If so, have you seen the following tutorial on using delta time? This may help.

https://coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/

Best regards,

Brent

Hi Brent,

Thanks for the reply. I would like to move the physics bodies and I want to know whether translating them manually is a good approach (Will it cause any problems?) or setting its linear velocity is the right way to do it?

Thanks

Hi again,

Either method is fine, but when using physics, I typically recommend that you use all the power that the physics engine gives you. So, in this case, I’d just assign a velocity to the object using “object:setLinearVelocity()”:

http://docs.coronalabs.com/api/type/Body/setLinearVelocity.html

The main reason to consider the delta time thing would be if you wanted the absolute most consistent linear movement rate, even during potential frame rate fluctuations. If you’re not too concerned about that, then using the physics method is fine for most instances.

Have fun,

Brent

That was exactly what I was expecting! Thank you Brent!