When dealing with
Rigidbody 2D, there are three key body types which determines how a game object move and react to collision. This post is the complete guide on how and when to use them.
- No REAL Rigidbody component attached to them, so physics engine does not consider them to be moving
- No collision can be applied to them, so
OnCollisionwill not work.
- Use case: ground, walls, other any other game object you don't want the character collide with
- Kinematic game objects are entirely driven by scripts, so you have to manually handle the the motion part:
- Kinematic game objects only process collisions with Dynamic game objects, i.e. bouncing away, and cause
OnCollisionEnterevent to be sent
- Use case: you want the character move with more flexibility
- Dynamic game objects are entirely driven by game engine (physical engine)
- The motion of Dynamic game objects are affected by force, velocity and etc
- The physics engine takes responsibility for resolving their collisions with static, kinematic, and other dynamic objects and rebounding them as needed
- Use case: game characters, moving game objects, etc
Physical Layer Collision Matrix Setting
This is especially useful when you want to customize the physical in your game. Say for example, if you have a game object A, with a dynamic rigidbody on layer Room, and you don't want it collide with other game objects if they are on layer Door, so you set up like this:
Edit -> Project Settings -> Physics 2D:
In the end, the collision between layer Room and layer Door will be ignored.