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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Constraining rigidbody2D - Stopping a rigidbody from moving

Discussion in '2D' started by Lewissss, Mar 10, 2014.

  1. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    I know that Rigidbody3d has an option to constrain the x, y and z positons... How would you achieve thks with a rigidody2D?
     
  2. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    105
    Check out the last reply in this post (by wccrawford).

    The topic is about constraining a rigidbody's rotation, but it should work for locking it in place all together.
     
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,495
    The solution talked about there "fixedAngle" only locks Rotation, it can't do anything else.

    OP, if you want the rigidbody to not move at all, then just set it to "isKinematic".

    Otherwise, if you want it to stay still, but still rotate when hit by things, then create another object at it's position, with a HingeJoint2D and Rigidbody2d set to "isKinematic" on it, then connect your main object to the "Connected Rigidbody" slot in your HingeJoint2D, and checkmark "Use Limits". Your rigidbody will now stay in place, but still rotate when hit by other colliders.
     
  4. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    That's an excellent idea!! Thank you very much!! :)