Search Unity

Rigidbody for character movement - Kinematic vs Dynamic

Discussion in 'Game Design' started by Dokuni, Aug 17, 2022.

  1. Dokuni

    Dokuni

    Joined:
    Mar 30, 2021
    Posts:
    9
    Hi everyone,
    I started studying Unity a few weeks ago and, to make myself more familiar with the editor, I'm trying to reproduce the first level of Super Mario Bros.

    Currently, I'm dealing with the character movement component and I decided to implement all the horizontal and vertical movements myself using standard physics formulas (uniformly accelerated motion, etc.).
    I am struggling with the type of the rigidbody that the character should have: kinematic or dynamic.
    Since the character should not be moved by other bodies (projectiles, monsters, etc.) I decided to make it kinematic, but the problem is that the collisions with obstacles don't stop the player.
    On the other hand, if I make the body dynamic I should handle all the collisions in a way such that the player is not moved by other elements in the scene.

    To summarise my study:
    - Kinematic
    Pro: other bodies don't affect my character
    Cons: collisions don't work in the proper way
    - Dynamic
    Pro: collisions work properly and my player movement is stopped by an obstacle
    Cons: other bodies affect my character

    Am I missing some concept to make things easier? Which could be the best solution?

    Thank you in advance :)
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Have you looked into the "Character Controller" component? It's specifically designed to cover this use case, as opposed to the physics built into a Rogodbody, which is meant to approximately simulate real physical reactions, which isn't what you want.

    Other than the Character Controller, you likely need to use a kinematic body and script the interactions you want the body to have with other colliders, which is quite a bit of work.