Last Updated: November 19, 2020
· pekalicious

Unity physics rules of thumb

  • A rigidbody is simply something that tells the physics engine to watch this object.
  • A collider is something that tells the physics engine where an object should collide with other objects. If the collider is a trigger, the engine will tell you when a collision happens (Collision detection), but will leave it to you to decide what to do upon collision (Collision response). If its not a trigger, the physics engine will handle collision response appropriately.
  • If you want collision on something it needs a collider. If this collider should move it MUST have a rigidbody.
  • If you want 100% fine control over that rigidbody (say, for a platformer character), it should be kinematic, and you should manipulate it with rigidbody.MovePosition() and rigidbody.MoveRotation(). Never EVER use the transform to move physics objects. Thats like sticking a fork into a toaster, scrambling it around and expecting the toaster to deliver toast :)
  • If you want to collide with objects that does never move (obstacles, walls etc), they should also have a collider, but not a rigidbody. This tells the physics engine that these objects will never move, and they are ignored when it does collision calculations (BOOM! you just saved compuation time for the fancy effects stuff)
  • If you want more realistic motion with a physics object, put a dynamic (non-kinematic) rigidbody on it, and give it a collider. Move it by using AddForce. Momentum delivered courtesy of PhysX, if you adjust the drag settings correctly.
  • If you are moving a rigibody over several frames, be sure to do it in FixedUpdate. If not, the physics engine is unable to calculate m/s properly, because Update is not run at a fixed interval. It runs as fast as it can (in most cases)
  • If things are still moving through walls, try enabling "Continuous" collision detection on the rigidbodies that move. Its slower to calculate, but more precise.

[via Reddit]

Related protips:

Improved PlayerPrefs for Unity