2015/03/29

Unity notes #1: Rigidbody VS Collider

While I am going through the tutorial roll a ball, I found that Rigibody and Collider confuse me a lot. I have to do a bit searching so that I can tell the differences between them.
To be honest, official document states the differences clearly. What I am writing below is a kind of rewording so that I know what is going on.

Definition from unity document

Rigibody enables your game object to act under control of the physics.
Collider defines the shape of an object for the purposes of physical collisions.

Similarity between Rigidbody and Collider

  • They are both components that can attach to game objects.
  • They both belong to the physics system in Unity.

Differences

Rigidbody

  • Usually, there is one rigidbody for a game object
  • Where physics take effect (Force, torque)
  • Variation of Rigidbody: isKinematic

Colliders

  • It is common for a game object to have more than one collider to form a compound collider
  • Where collision take effect (2 colliders crashes. Note that at least one Rigidbody must be attached to one of them)
  • Variation of Collider: isTrigger

Pitfalls

Game object falls through the floor plane

Reason
  1. IsTrigger, property of a collider, has been switched on for that game object. No collision occurs between that game object and the floor. Or
  2. There is no colliders attached.
Solution
For 1,
  1. Turn off IsTrigger or
  2. Turn off Use gravity for the rigidbody or
  3. Turn on Is kinematic for the rigidbody
For 2,
  1. Attach a collider

Move static colliders

Reason
A static collider means there is at least one collider attached and NO any Rigidbody attached. Unity assumes this kind of colliders won’t move so that they can make optimisations.
If you moving them during game play, it degrades your game performance a lot.
Solution
  1. Do not move those colliders. Or
  2. Attach a kinematic Rigidbody to that game object

Puzzles

  • For colliders, turn on IsTrigger or not?
In term of behaviours, other objects cannot pass through colliders without turning on IsTrigger. Therefore, whether or not turning on IsTrigger depends on your situations.
  • For Rigidbody, turn on IsKinematic or not?
(Rigidbody + kinematic + Collider + trigger) behaves similar to a static collider. However, moving this kind of game objects won’t degrade our game performance as the static does.

1 則留言: