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

Making a hanging light, swing side to side....

Discussion in 'Physics' started by AEBlob, Apr 11, 2016.

  1. AEBlob

    AEBlob

    Joined:
    Nov 20, 2015
    Posts:
    53
    OK, so I'm making a 2D platformer game and in a few rooms I have hanging strip lights à la...

    upload_2016-4-11_12-45-18.png

    The chains are separate sprites from the main body of the light, and separate from each other (the chains length can be adjusted with ease). Basically, I wanted to get the strip light, when the Player makes contact with it, to detach from the chain on one side, and just swing for a bit on the other chain until it naturally reaches a stop.

    How I am to do this? I have no idea, so I thought I'd pick you guys and girls brains to see how you would do it? :)
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Have you tried playing around with joints? This sounds like a perfect fit for a HingeJoint2D. Give the lamp object a Rigidbody2D, and optionally make its collider a trigger if you don't actually want physical interaction between it and the player.

    Then set up triggers on the chains and rig them to disconnect the corresponding HingeJoint2D. This sohuld get you close to the effect you were looking for. You can set up more than one hinge for each chain link if you want, too.
     
  3. AEBlob

    AEBlob

    Joined:
    Nov 20, 2015
    Posts:
    53
    Hey that's great man thanks. First time I've used the hinge joint, I love it. Is it going to add much size to the game file if I have this on several lights?
     
  4. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Not size, no; it will technically make scenes more difficult for CPU's to calculate, though. No idea of the extent, so you'll have to test for slowdown.