Physics and Colliders
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
- Create a Plane Primitive (GameObject -> Create Other -> Plane) and scale it up. We'll use this as the "Ground Plane."
- Create a Box Primitive (GameObject -> Create Other -> Box) directly above the Plane.
- 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.
- You can modify the properties of a Rigidbody in various ways to adjust how the Physics will work.
- Hit Play to watch the box fall and land on the plane.
- 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.
- Mesh colliders are found under Components -> Physics -> Mesh Collider.
- 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).
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
- 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.
- 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