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 '2D' 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-27-35.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? :)
     

    Attached Files:

  2. AEBlob

    AEBlob

    Joined:
    Nov 20, 2015
    Posts:
    53
    Maybe I should just add, so far, the chains have no physics of any kind, and all it is, is essentially empty sprites with a simple BoxCollider2D on the main body of the light.
     
  3. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Have you tried playing around with joints? This seems like a perfect fir for HingeJoint2D. Give the lamp object a Rigidbody2D and optionally make it a trigger if you don't want interaction with other Rigidbody's.

    Add hinge joints and connect them to your chains, which will also need Rigidbody's, then rig some triggers that are scripted to disconnect the joints when the player touches them. You can also add joints to hinge each chain link to the next one, if you like.

    EDIT: Ok, I thought I was crazy for a minute, but you did post this more than once. I'd say it's best for everyone if you keep each question to one post in one subforum.
     
    Last edited: Apr 11, 2016