Search Unity

Pivot problem when using Rigidbody2D and BoxColliders

Discussion in '2D' started by Squirrel121212, Nov 8, 2017.

  1. Squirrel121212

    Squirrel121212

    Joined:
    Sep 22, 2017
    Posts:
    7
    Hey, so recently I was messing around with my project and I used the addtorque method from RB2D to rotate a block around my player. I created the pivot point of this object by having a parent object sit at the center of my player while the block was its child. However, when I add a box collider2d to my block, the new pivot point of rotation becomes the center of the box collider. Any ideas on how to change the pivot to my player?
     
  2. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    432
    You should be rotating the parent object, not one with collider. And if the object needs a rigidbody, it should also be on the parent. If you want to show a screenshot too it would help.
     
  3. Squirrel121212

    Squirrel121212

    Joined:
    Sep 22, 2017
    Posts:
    7
    It's really weird, it works perfectly when I disable the box collider I even double checked to make sure I'm rotating the parent object while the box collider is on the child gameobject.
     

    Attached Files:

  4. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,219
    Seems your adding to the wrong object.

    EDIT: also if you add a collider and it starts behaving weirdly, its likely beginning to collide with stuff. Try debugging using an IDE to see what is reporting collision callbacks. If you don't know how to debug yet, then instead try logging out stuff to the console using Debug.Log. I recommend looking up how to attach to a IDE debugger if your unsure about how to do that though, as its a must have skill to fix bugs.
     
  5. Squirrel121212

    Squirrel121212

    Joined:
    Sep 22, 2017
    Posts:
    7
    I found the solution, I just had to change the center of mass using rb.centerofmass
     
unityunity