x


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.

more ▼

asked Jun 03 '12 at 11:08 AM

MithosAnnar gravatar image

MithosAnnar
299 22 36 41

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

Jun 07 '12 at 02:28 PM Fattie
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jun 04 '12 at 04:15 PM

Owen Reynolds gravatar image

Owen Reynolds
12.2k 1 7 46

Thanks Owen, your the best!

Jun 07 '12 at 01:33 PM MithosAnnar
(comments are locked)
10|3000 characters needed characters left

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?

more ▼

answered Jun 03 '12 at 03:42 PM

Owen Reynolds gravatar image

Owen Reynolds
12.2k 1 7 46

Owen, they could possibly avoid that problem (and eliminate 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:

  1. Hello! Game engines do physics. Do not start calculating any physics.

  2. 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.

  3. 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!

Jun 03 '12 at 04:31 PM Fattie

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.

Jun 04 '12 at 06:57 AM MithosAnnar

You could add a jump animation so that the members move according to it while in the air.

Jun 04 '12 at 07:16 AM fafase
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1947
x1071
x353
x107

asked: Jun 03 '12 at 11:08 AM

Seen: 603 times

Last Updated: Jun 07 '12 at 02:29 PM