Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Full movement controll with rigidbody?

Discussion in 'Physics' started by Cyrus2004, Sep 1, 2023.

  1. Cyrus2004

    Cyrus2004

    Joined:
    Jan 21, 2023
    Posts:
    1
    Hi. I'm working on a 2D game with my friend, completely new to game development. For movement, it's tempting to use rigidbody to make the physics easier to do and more realistic. However, I need full controll over the character movements from time to time. Is player controller, rigidbody, or something else the best way to do this?
     
  2. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    79
    rigidbody is much more flexible in the long run, say if you decided you want the player to be thrown back by an explosion or some force it would be much easier with rigidbody. you can alter the velocity directly so the world is your oyster with one.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,740
    What about the Rigidbody2D doesn't give you "full control"? There are three different body-types available, not simply Dynamic which gives you dynamic collision detection and response, gravity, forces etc. There's Dynamic, Kinematic and Static.

    Use Kinematic and it does nothing. You ask it to move, it moves. It doesn't get moved by anything it touches, isn't affected by gravity etc.

    There's far too much misinformation around about Rigidbody(2D) due to lack of understanding so I would suggest looking at the three available body-types, which are common across pretty much all physics systems both 2D and 3D, to see what suits your needs.

    Know though that colliders don't move (ever!) but Rigidbody do and colliders are attached to them so you should never modify the Transform as this just causes a Collider without a Rigidbody2D to be recreated from scratch so bad for performance. Add a Rigidbody2D, select the body-type which suits and always use the Rigidbody2D API to cause movement i.e. MovePosition, Velocity etc.