Physics and Colliders

From ETC Public Wiki
Jump to: navigation, search

Note: Unity uses the nVidia PhysX physics engine.

Go here for an in-depth guide on Physics and Colliders: http://unity3d.com/support/documentation/Manual/Physics.html http://unity3d.com/support/documentation/Components/comp-DynamicsGroup.html


Creating a Basic falling Box

  1. Create a Plane Primitive (GameObject -> Create Other -> Plane) and scale it up. We'll use this as the "Ground Plane."
  2. Create a Box Primitive (GameObject -> Create Other -> Box) directly above the Plane.
  3. Select the Box and add a Rigidbody Component (Component -> Physics -> Rigidbody). The Rigidbody component what causes the object to be affected by Physics. In order for a collision between two objects to happen, they both need to have colliders and at least one of them has to have a Rigidbody component. Primitives in Unity are automatically created with colliders, so you don't have to worry about that in this basic tutorial.
  4. You can modify the properties of a Rigidbody in various ways to adjust how the Physics will work.
  5. Hit Play to watch the box fall and land on the plane.


Collision Meshes

  1. Aside from the standard box, sphere and capsule colliders, there is also the option of a mesh collider. As the name implies, Mesh colliders are in the shape of whatever mesh is assigned to it. For example, it is possible to create a mesh in the shape of the letter Y.
  2. Mesh colliders are found under Components -> Physics -> Mesh Collider.
  3. Once the component is added, open the object in the Inspector and assign a mesh to it (see Figure 1). File:Meshtomeshcollider.png

Collision for Animated Characters

Note: The mesh collider does not animate. This means that if you want accurate 1:1 collisions for animated characters, it will need a series of colliders parented to each joint roughly the same shape as the character.

Another way to do this is to make a ragdoll out of the character and turn off (or remove) the rigidbody components. If you just want generic collisions for humanoid characters, you may use a Character Controller (below).


Character Controller

To use a collider for a controlled character without using Rigidbody Physics, use Character Controllers.

Learn about Character Controllers here: http://unity3d.com/support/documentation/Components/class-CharacterController.html


Physic Materials

  1. All colliders can have a "Physic Material" assigned to them, controls how the physics work with that particular collider. For example, Physic Materials can be used to make a really bouncy surface or a surface with a lot of friction.
  2. To create a Physic Material, go to: Asset -> Create -> Physic Material.

Go here to learn more about Physic Materials: http://unity3d.com/support/documentation/Components/class-PhysicMaterial.html