Search Unity

Chain using HingeJoint2D and collision

Discussion in '2D' started by Pearbook, Dec 9, 2015.

  1. Pearbook

    Pearbook

    Joined:
    Feb 3, 2013
    Posts:
    7
    Heey,
    I made a oil lantern on a chain for my 2D game as a background object. I used 2D HingeJoints to make this and it works really nice. The only problem I have is, is that if I want the lantern to move I have to add a collider and walk against it with my player. Which is fine, it looks just like I want it. Now the problem is that the collider on the lantern effects the player. This means that the player can stand on top of the lantern and gets stopped by pushing the lantern (which I don't want).

    In the GIF below you can see how it looks at the moment:


    I also was thinking of using this method for other things as well like hanging ropes and plants. So I was wondering if someone knows a way to make my chain move without collision on the lantern? (without making it look odd)
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    You could use a trigger and when a OnTriggerEnter2D is called, you could impart the velocity of the object entering the trigger to the body on the lamp either directly or via a force. This way, the object entering the lamp trigger won't be affected.
     
  3. Pearbook

    Pearbook

    Joined:
    Feb 3, 2013
    Posts:
    7
    Ow wow, I feel pretty stupid now. For some reason I was thinking to difficult and made it more difficult than that it
    actually was. Thank you so much and sorry for the stupid question.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Not stupid at all; asking questions is how we all learn. Feel free to ask away.