Search Unity

Difference Between Static and Dynamics Game Objects

Discussion in 'Physics' started by Deleted User, Mar 10, 2022.

  1. Deleted User

    Deleted User

    Guest

    The Roll-a-Ball tutorial (https://learn.unity.com/tutorial/de...uv=2019.4&projectId=5f158f1bedbc2a0020e51f0d#) (section 5: add a rigidbody component to the pickup prefab) states that any game object with a collider and a rigid body is considered dynamic, and that we want to mark our pickup objects as dynamic to "boost performance". The explanation was quite uninformative and has left me wondering why we don't make ALL objects dynamic in order to gain this supposed boost in performance. I tried finding more information online, but perhaps my research skills are lackluster. Could someone explain this in further detail or leave a link to an explanation of what is going on? Thanks!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    There are three types of Rigidbody(2D) supported.

    Static - Is not affected by external forces (collisions, gravity etc) and is optimised to never move. This takes the least processing by the physics system as it can make assumptions about what it can take part in. Static therefore don't interact directly with anything but other Dynamic body types can interact with it though.

    Kinematic - Is not affected by external forces (collisions, gravity etc) but instead is optimized to be moved explicitly i.e. MovePosition and MoveRotation etc. This takes more processing by the physics system. Kinematic don't interact directly with anything but Dynamic body types can interact with it though. There is an exception here where you can ask that contacts be created but you don't get a collision response still. Kinematic are also the only body types that Unity have set-up so that when in a child hierarchy, they'll naturally follow a parent Rigidbody(2D) that is Kinematic or Dynamic.

    Dynamic - Is completely affected by external forces (collisions, gravity etc) and is optimized to move via forces/velocity i.e. AddForce and AddTorque etc. This takes the most processing by the physics system. Dynamic always interact with any body type.

    In short:
    Static = Don't Move, these are non-moving things like platforms, buildings.

    Kinematic = Move explicitly but won't react to collisions, these are moving things like platforms or players where you don't want automatic collision response and use queris to detect the surroundings (used in character controllers)

    Dynamic = Full rigid body responses. Use for things that need to bounce, have friction, work with gravity and react automatically to collisions, work with joints/constraints and have "realistic" physics.

    This applies to 2D and 3D physics and to most physics engines inside and outside of Unity.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    To add, I have no idea about that tutorial but Dynamic bodies, from a physics point-of-view, are the opposite of "boosting performance".
     
    BeyondMASC likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    That's incorrect. Go to the Rigidbody2D and there's a body-type to allow you to explicitly select the body-type of Static, Kinematic or Dynamic.

    In 3D though, there is not such field and it only lets you use a toggle of "IsKinematic". When this is off, it's Dynamic, when on it's Kinematic. So what about Static in 3D? Well Unity has some implicit behaviour though to be aware of. If you add a Collider(2D) but don't add a Rigidbody(2D) then Unity adds the Collider implicitly to a Static body that is hidden known as the Static ground-body. This is just an convenience to save you adding bodies when you just want something Static.

    You'll see people say things like, "to make it react to collisions, you have to add a Rigidbody(2D)" and whilst that is technically correct, it's vague. The only thing that reacts to collisions is a Dynamic Rigidbody(2D) so yes, you need to add a Rigidbody(2D) but you also need to make sure it's Dynamic.

    The reason why the statement you mentioned is incorrect is that if I were to add a Rigidbody and set it to be Kinematic then it wouldn't be Dynamic. ;)
     
  5. Deleted User

    Deleted User

    Guest

    Thank you for the detailed response! Unity might want to check out that tutorial if it's giving out straight up false information though. I think I've understood everything you've said, so thank you again!
     
    MelvMay likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    You should report this yourself to the Learn team here so you can also add what and why it was confusing. Obviously you can add that any passages of text are wrong and link this thread here.

    "Unity" as a singular thing doesn't exist to perform actions like correct tutorials and poor language usages so you should report your experience there for sure! To be clear, I have no way to correct this either!