- Home /
Using HingeJoint2D to Join Objects at Specific Points
My end goal is to create a rope bridge similar to what can be seen in the picture below, which is built from a number of different planks, which when walking over will apply a downwards force and cause more curvature at the point of pressure.
I have been trying to achieve this using the Hinge Joint 2D components, however my attempts have all failed so far, and I am wondering if there is a better component to be using to achieve this or not.
Any advice on how best to approach this would be much appreciated. Thanks!
Answer by rastating · Jan 12, 2014 at 02:02 PM
I fixed this in the end using the Hinge Joint 2D components by having two kinematic rigidbodies at both ends of the bridge and then linking each one to the one to the left of it (leaving the starting one without a connected rigidbody). After doing that I altered the anchors to ensure they were always at the end of the bridge piece rather than in the middle (this is where I was going wrong all along).
Sorry, I became somewhat occupied. Glad you got it to work. =)
No problem, thanks for offering your assistance anyway, I appreciate it :)
Remember to mark your question as answered as well. =)
I have tried but it says there is already an accepted answer and won't let me :(
Ins$$anonymous$$d of setting the ends to is$$anonymous$$inetic, I duplicate the ends (i.e. extended it), remove Colliders and SpriteRenderers, set it to is$$anonymous$$inemtic, so that we can move the real ends around and still have the 2 "visible" ends react to physics accordingly.
Answer by GameVortex · Jan 11, 2014 at 09:08 PM
Hinge Joints are mostly for rotation. What you want is the **Spring Joint** which acts as a spring between rigidbodies. Connect one between all your objects and tweak the dampening and distance until the desired effect is achieved. You probably want the distance pretty small so the springs can't be stretched too far.
Hey, thanks for the response! I've been playing with the Spring Joint and I think it is definitely a step in the right direction, but it seems the joint is always formed in the centre of my game objects, regardless of how I am tweaking the anchor points in attempts to make each plank join on the left and right hand sides of one another. Have you got any advice on what I may be doing wrong?