Search Unity

2D Hinge Joint & Motor Not Working

Discussion in '2D' started by OceanBlue, Oct 23, 2014.

  1. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    Hi,
    I've read the forums, and followed the Unity video tutorials, but can't get my 2d objects to work.

    I have a box hanging from a tree branch.

    So on the branch I have a 2DRigidbody with isKinematic set to true.

    The box is a child of the branch above. It has a 2DRigid and a 2d Hinge Joint.
    The hinge joint is connected to the branch's rigid body, and motor ticked with speed set to 100. The box's rigid body is NOT set to isKinematic.
    The Anchor and connected anchor on the box have been moved so they're in the same position, connecting to the branch at the top of the box.

    Gravity on the box set to 1, mass 2.

    When I press play nothing happens. If whilst playing i physically move the branch itself along the x axis, the box of course moves with it, and starts rotating 360 degrees non-stop (why can't it do this at start up? Why do i have to slightly move the branch???)

    What I want to achieve is on start up, that the box starts swinging left to right (rotation on the z), as though the wind is blowing it.

    Any assistance would be appreciated, as I'm pulling out my hair over this.

    Thanks
     
  2. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    This isn't the first time I've heard of physics objects needing to be awakened. Might be a bug. Try giving it a tiny kick in its Start function; a slight AddForce, for example. Or have the Start function set the motor.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    This sounds very much like an issue recently discovered. If this is the case then it has been fixed in 4.5.5p2 (not yet released). Essentially when the joint is added to the rigid-body, Box2D doesn't wake the respective bodies so the fix was to do this inside Unity as an explicit step.

    You can either wake the rigid-body explicitly in the start function using 'Rigidbody2D.WakeUp()' or (not preferred) set the Rigidbody2D 'Sleeping Mode' to 'Never Sleep'.
     
  4. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    Thanks. I've put WakeUp() in the script, i've added force, and i've also put it to never sleep mode just in case. Still no movement.
    This is so so frustrating.

    All i want is for my box to dangle from the branch, rocking back and forth. So simple, yet so difficult to implement. Why?!!
     
  5. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    OK so the object will only move if it has a collider on it and hits something. Aside from that, nothing else works to get it started
     
    Last edited: Oct 23, 2014
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Just in-case it's a bug, would you mind submitting a reproduction project and giving me the case number? I can take a look at it for you.