- Home /
Problem with joints
I am trying to make a 2d game. I have a character who jumps made of segments, one big and four little ones. all of the segments are planes with colliders and rigid-bodies attached. I want the little segments to swerve behind the big one when i jump. To accomplish this I have attached hinge joints to most of the segments, but this has not worked, the segments swerve but when he jumps he bowls himself over and usually lands on his head.
Does anyone know how I would implement this effect?
any help would be greatly appreciated.
EDIT: for clarification my character is a worm made of five segments, all of which are children of one empty game object representing the character as a whole. The biggest segment is at the front and is the creature's head while the four little ones are the tail. My movement script which I have placed on the head segment, works by changing the head segment's velocity, so the rigid bodies on the tail segments are interfering with my jumping. I would like the head to be the centre of physics and interaction with the world while the tail just gently swerves behind the head when he jumps, not affecting the movement at all.
make the tail have zero mass. (ie, don't use the physics engine for the tail). add two lines of code to make it "wiggle gently".
it's that simple
Answer by Owen-Reynolds · Jun 04, 2012 at 04:15 PM
NOTES: The tail wants to spin the body around, and even a very light tail is enough to do that. Like a 300 pound ice-skater who throws out a 10-pound arm to start spinning. For real, an animal is moving the tail in a very precise way to control their spin. In other words, instinctively running physics "backwards" in it's head. I don't think even state-of-the-art robotics can do that, yet. So, there's no way Unity can make a correct "active" tail.
SOLUTION: The trick to is to wall off the tail from the body. This worked for me: add a child "rump" to the head segment. It could be an empty or a model. Give it a rigidbody set to isKinematic
(so, it's not really a rigidbody, but counts as one for technical reasons. See why later.)
For the tail sections, same as before, but connect the first one to the new "rump" (the slot for connectedBody requires a Rigidbody. Using an isKen RB as a frozen connection spot is a trick from the Docs.)
The tail is now stuck to a single point in space, which just happens to follow to head. One problem I had is that the tail can still bend and smack the body, knocking it around. You could just make the joints stiffer. Or, an absolute solution would be to make a wide collider between head/tails on a layer only the tails can hit.
Answer by Owen-Reynolds · Jun 03, 2012 at 03:42 PM
Try increasing the main body's Mass, in the rigidbody (can do through the Inspector.)
Unity just sets everything to 1 kilogram(*), regardless of how large the collider is(**). This means physics is acting as if your tail segments are brass and your body is a giant feather pillow -- easily pulled around by the tail.
(*)Kilos are mass and weight? That doesn't sound right.
(**) Maybe they should throw a card for "set default Mass proportional to Collider volume" at the bottom of the scrum pile. But then they'd want to recalc when the collider was resized, but only if they're still on default. Instantiated prefabs have a "never been touched by user" flag. Do things such as Mass have one?
Owen, they could possibly avoid that problem (and eli$$anonymous$$ate 30% of all questions on this forum) by simply:
having an enormous flashing, red and green, neon alert that appears - full screen animated glowing neon - with massive alarm sound effects playing in the background which says in all major world languages:
Hello! Game engines do physics. Do not start calculating any physics.
You must use real-world sizes. You must use real-world sizes. You must use real-world sizes. You must use real-world sizes. You must use real-world sizes.
You must set mass properly.
At the bottom, have a "Do not show this again" button, but actually don't make it do anything. Just keep showing that alert - forever!
I have tried fiddling with the mass, but while he now usually lands on his feet he still acts like a maniac when he's in the air. It seems to me that having rigid bodies my on the tail segments, no matter how small or large the mass interferes with jumping causing unrealistic and poor looking movement.
You could add a jump animation so that the members move according to it while in the air.
Your answer
Follow this Question
Related Questions
2D (With Planes) Jump Script 0 Answers
Rigidbody2d not falling once in the air 1 Answer
2d crane physics hinge joint 2d 0 Answers
Incremental jump while pressing Jump button 0 Answers
Sphere Goes Crazy 3 Answers