Updating physics on object in

01 Apr

These are tips for using Rigid Bodies and Physics in Unity.

I was maintaining these in a document on my PC and decided I may as well store them publicly so other people can benefit from what I have learned: Non-kinematic rigid bodies will ignore the hierarchy.

This is perfectly fine, and gives us smooth visual results.

However, because the time in physics world is different, objects updated in the regular update loop appear to move erratically in the physics world.

If you make one rigid body a child of another and translate the parent. The child’s transform will update so that it remains in place in world space.

If you want to couple rigid bodies you need to use joints.

You can also apply your own forces and impulses to a body.

updating physics on object in-27updating physics on object in-22

Note that you need not attempt to provide realistic values for physical quantities—use whatever values produce the behavior or gameplay you’re looking for.

If you are lucky enough to have your physics delta time match the display rate and you can ensure that your update loop takes less than one frame then you have the perfect solution for updating your physics simulation.

But in the real world you may not know the display refresh rate ahead of time, VSYNC could be turned off, or perhaps you could be running on a slow computer which cannot update and render your frame fast enough to present it at 60fps.

Same thing for a display refresh rate of 75HZ instead of 60HZ or even the case where VSYNC is turned off on a fast computer: But there is a huge problem with this approach which I will now explain.

The problem is that the behavior of your physics simulation depends on the delta time you pass in. It’s much more realistic to say that your simulation is well behaved only if delta time is less than or equal to some maximum value.