- Home /
Hinge Joint Segments rotating offscreen
I am making a 2d game and have a worm for a character. the character is made of 5 segments connected by hinge joints, 1 big one for the head which is what interacts with the world, and 4 small ones for the tail which just sways behind the head. to stop the tail messing up my jumping (which works by changing the head's velocity) the segment closest to the head is attached to a kinematic rigidbody which follows the head. That all works but when I jump left the tail tries to stay to the left. I assume this is because of my hinge joints min and max values so I have made this script
function Update () {
vell = player.rigidbody.velocity;
if (vell.x < 0) {
hingeJoint.limits.min = 180;
hingeJoint.limits.max = -180;
}
if (vell.x > 0) {
hingeJoint.limits.min = 0;
hingeJoint.limits.max = 0;
}
}
but when I try to jump nothing happens until and an objects collides with my tail segments. This causes them to rotate, slowly at first on all axes which looks very bad as they are planes. Then when I try to jump again it works but my tail segments start flying tens of thousands of units offscreen.
Thanks in advance for any help.