EloiStree / HelloUnityKeywordForJunior

List of word nice to learn for Unity3D
0 stars 0 forks source link

Keyword: Kinematic #281

Open EloiStree opened 1 week ago

EloiStree commented 1 week ago

Dynamic vs static vs Kinematic image https://youtu.be/xp37Hz1t1Q8

EloiStree commented 1 week ago

🤖 In Unity, Kinematic refers to a type of object behavior in the physics system, typically applied to Rigidbody components. When you set a Rigidbody to kinematic, you are telling the physics engine to treat the object differently from dynamic objects, which are affected by forces such as gravity, collisions, and other physical interactions. Kinematic objects are not influenced by the physics engine but can still affect other objects.

Here’s what happens when you mark a Rigidbody as kinematic:

Key Features of Kinematic Rigidbody:

  1. No Physical Interactions: A kinematic Rigidbody will not be affected by forces like gravity or collisions. It won’t respond to impacts, meaning it won’t move or rotate unless you explicitly change its position or rotation in code.
  2. Direct Control: You move or rotate a kinematic Rigidbody manually, typically by modifying its transform (i.e., changing position or rotation directly) or using functions like Rigidbody.MovePosition() and Rigidbody.MoveRotation().
  3. Affect Dynamic Objects: While a kinematic object doesn’t respond to physical forces, it can still affect other dynamic objects in the scene. For example, if a kinematic object moves and collides with a dynamic object, the dynamic object will react accordingly.

Why Use Kinematic Rigidbody?

  1. Player-Controlled Characters: Kinematic Rigidbodies are often used for player-controlled objects, such as characters or vehicles, where you want to move the object through code without being affected by physics forces like gravity or collisions. This allows for precise control.
  2. Moving Platforms: Kinematic Rigidbodies are great for things like moving platforms, where you want to manually control their movement, but still want them to affect other dynamic objects (e.g., a character standing on the platform).
  3. Animated Objects: Objects that are animated (through Unity’s Animator system) often use kinematic Rigidbodies, as the movement is handled through animation rather than physics.
  4. Non-Interactive Physics Objects: If you have objects that move in a specific way (like doors or elevators), but don’t need to respond to gravity or other forces, making them kinematic is a good option.

How to Set a Rigidbody to Kinematic

In Unity, you can set a Rigidbody to kinematic either through the Inspector window or in code.

Example Use Case:

If you have a character controlled via keyboard input, you typically want precise movement and don’t want the character to be knocked over by small collisions or affected by gravity when jumping or falling. Setting the character’s Rigidbody to kinematic lets you manually control the character’s position, while still allowing them to interact with the physics system (like pushing other objects or triggering collision events).

In summary, using kinematic Rigidbodies is ideal when you need direct control over an object’s movement and rotation, rather than relying on physics simulations, while still allowing interactions with other physical objects in your scene.