Search Unity

Non-Static, Non-Dynamic Collider + Rigid Body Best Practices

Discussion in 'Physics' started by AnthonyReddan, Nov 29, 2019.

  1. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    17
    Hi there,

    I understand it's desirable performance-wise for colliders whose transform is controlled procedurally to be associated with a kinematic RigidBody.

    What's unclear to me, is if we gain any benefit out of doing this if the transform is manipulated completely outside of physics - i.e. without using RigidBody.position/MovePosition/MoveRotation/etc. and instead only through manipulation of GameObject.transform.

    We have 3 separate cases in our project where a blackbox system is updating the transform of a game object and we want a collider on that GameObject.

    In such cases, is there any benefit to having a kinematic rigid body?

    Thanks,
    Ant
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,938
    MovePosition/MoveRotation are NOT outside of physics. In fact they uses Physics to move them. It's integrated in physics., that's why they are commands. What they do is create the correct velocity to reach the desired position or rotation by the next physics update.

    This is so people can quickly move things without tunnelling and other issues.

    The only way to teleport outside of physics is to affect the transform directly.
     
  3. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    17
    I think you misread, I said if you move a game object WITHOUT using those functions (so, gameobject.transform.position = Vector3.zero; or whatever)
     
    hippocoder likes this.
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,938
    I see I did!
     
  5. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    17
    FYI, if anybody stumbles across this. I never got a definitive answer, however I found this:
    https://docs.unity3d.com/ScriptReference/Rigidbody-position.html

    Thing is, the rigid body is kept in sync with the transform so I don't see why the colliders would have to recompute anything if the rigid body is attached to the transform you're moving.

    So in the end, I'm operating under the assumption that yes, it is better to have a kinematic Rigidbody with your colliders even if you don't have control over how the transform is being updated.