If you’ve ever used a Rigidbody component in Unity, you may have seen a couple of settings on the component which may be a little difficult to understand the meaning of. On this site, we have covered what some of these settings mean and what they do, such as:
- The Collision Detection property, which controls what kind of collision detection mode your Rigidbody is using. This is because using the wrong Collision Detection mode can cause tunnelling.
- The Interpolate property, which controls how a Rigidbody’s position updates, and prevents things like camera jitter when used properly.
However, we’ve never covered what the Is Kinematic property does in Unity’s Rigidbodies.
1. What is a rigid body?
To understand what is a kinematic, it is helpful for us to first understand what a rigid body is. A term borrowed from physics and engineering, rigid bodies are idealised objects that do not deform under the influence of external forces. Instead, they maintain their shapes and sizes, making them ideal for analysing mechanical systems in physics and engineering.
In Unity, the Rigidbody
component does 2 things when attached to a GameObject:
- Detects and resolves collisions between colliders. This means that, in every physics frame, it detects all rigid bodies with overlapping colliders and separates them.
- Provides physics behaviour. After separating overlapping objects, the
Rigidbody
component also calculates how these overlapping rigid bodies exert forces on each other after collision.
Typically, Rigidbody
components are used for (2), to add physics behaviour to GameObjects, as shown in the animated image above. However, it is also important to note that for Unity to register collisions between 2 GameObjects with colliders, at least 1 of these GameObjects has to have a Rigidbody
component. Otherwise, the collision won’t be detected.
Article continues after the advertisement:
2. What is a kinematic?
When you make something a kinematic, what you are essentially trying to do is disable (2), the physics behaviour of a Rigidbody
component. This means that a kinematic Rigidbody
does not get affected by external forces. In essence, they can still push other rigid bodies, but they cannot be pushed by other rigid bodies.
The short below illustrates this:
In a sense, you can also say that kinematic rigid bodies behave like Thor’s hammer.
Note that when you make a Rigidbody
kinematic, you will not be able to manipulate it by using rigidbody.AddForce()
or rigidbody.velocity
any longer. The only 2 ways to move a kinematic Rigidbody
are:
- By applying animations on them, or;
- By moving them with code.
3. What are kinematics used for?
While the imagery of Thor’s hammer makes kinematics sound really cool, they are often used for rather mundane things in video games in reality, such as:
a. Moving platforms
This is actually the best example you can use to explain what kinematics are. As moving platforms are responsible for transporting players from one point to another, they have to have 2 important traits:
- They need to be able to collide with objects, otherwise you cannot stand on them.
- They cannot be affected by physical forces, or they will be knocked out of their defined paths.
As it happens, kinematic rigid bodies provide these 2 functionalities perfectly.
Article continues after the advertisement:
If you’d like to get some code for setting up moving platforms, you can refer to the article below.
b. Animated obstacles or platforms
A close relative to the moving platform, almost anything that is animated and serves as an obstacle or platform of some kind (e.g. elevators) that cannot be moved is usually a kinematic, for the same reasons as the moving platform.
c. Player characters
Player-controlled characters are often kinematics, because they should not be susceptible to other forces acting upon them when the player is controlling them. There can be exceptions to this case, however, depending on how the mechanics of the player character are coded.
In Unity, if you are using a NavMeshAgent
or CharacterController
to provide movement to your characters, note that your characters will be unable to push other rigid bodies around by default. If you want that functionality, you will also have to add 1) a collider and 2) a kinematic rigid body to it.
d. Projectiles
Projectiles are another obvious candidate for being kinematics. Again, this depends on the mechanics of the projectile itself. If your projectile follows a preset path when fired, then you will want to use a kinematic rigid body to drive it.
4. Conclusion
I hope this short article helped to give you a clearer idea of what a kinematic is, and when you should use them. If you have any useful information you’d like us to add to the article, please leave it in a comment below!
Article continues after the advertisement: