#Is it good practice to attach a rigidbody to everything that moves?

1 messages · Page 1 of 1 (latest)

austere heron
#

Say I have a bunch of doors and moving platforms and stuff in my level.
Normally I would just use transform.position to move them, however I've learned that this is not the best practice.
See here: https://forum.unity.com/threads/is-adding-rigidbody-to-every-moving-collidable-object-a-good-practice.253802/#post-8558909
According to this thread, it is good practice to put a rigidbody on everything and not move them with transform.position. But there is some doubt there, see the comment I linked to. People are unsure if this is the best practice right now.
(also keep in mind the objects can be collided with - players can walk up to doors or stand on moving platforms)

So the question is - for all the doors and moving platforms and everything that moves in my level - I should attach a rigidbody to them and move them using RigidBody.MovePosition instead?
(And transform.position is bad since that apparently causes everything in the scene to recalculate every frame?)

dreamy gulch
#

Hello and thank your for your patience. For moving objects like doors and platforms in Unity, especially when they interact with players or other physics elements, it's generally better to use Rigidbody and RigidBody.MovePosition. This method ensures realistic physics interactions and avoids issues that can arise from directly changing transform.position. While concerns about performance exist when frequently updating transform.position, they're usually significant only in complex scenes. So, in your case with interactive moving objects, attaching a Rigidbody and using RigidBody.MovePosition is the recommended approach for consistent physics behaviour.

austere heron