x


How to use multiple spring joints on the same object?

I'm trying to implement physics in a fashion similar to World of Goo, with multiple nodes connected in a mesh of springy constraints. I've been able to implement this in codebases other than Unity (such as Box2D) with spring constraints. Unity's spring joint looks perfect for the task, but unity won't allow multiple SpringJoint components on the same object, which makes that unworkable (as far as I know).

The ConfigurableJoint component DOES allow duplicate components, but the settings for it are a pain to figure out and I can't get it to approximate the spring joint. If I could, that would solve my problem, but so far experimenting with the values hasn't yielded anything.

What would be my best approach for implementing this? Is there a straightforward way to configure the configurable joints to do what I want? Is there another approach entirely I haven't considered?

Thanks!

more ▼

asked May 23 '11 at 03:27 AM

starstriker1 gravatar image

starstriker1
18 4 6 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Child objects of the GameObject with the Rigidbody can each have a SpringJoint on them. You'll probably wand to model it that way anyway as the joints need to be created and removed dynamically in your game.

more ▼

answered May 23 '11 at 04:25 AM

Waz gravatar image

Waz
6.5k 22 33 71

Thanks, that appears to do the trick. However, to get it to work I needed to add two joints to the child object: a fixed joint to secure it to the parent object (which it was acting independently of) and a spring joint to connect to another. This seems wasteful: I have one more joint and one more rigidbody than I need for every link I create. Is there a way to optimize this?

Thanks!

May 23 '11 at 08:16 PM starstriker1

This method Warwick describes works for me, I am using SpringJoints on the hair and hands of a character to get secondary animation on them based on their parent's motion. In my case I am not using fixed joints. For each thing I want floppy, I:

  • Create an Empty GameObject (I call them null points) called "Anchor"

  • place it at the point of the neutral position of the appendage I want floppy and Parent it to that child object or bone (By the way I would use bones or null points to do your world of Goo style thing)

  • Add a Rigidbody to that Anchor point and set the IsKinematic on

  • Create a 2nd Empty GameObject called "Springy" and position it near but a little bit away from the Anchor - but DO NOT parent this one

  • Add a RigidBody to Springy and turn its Gravity on

  • Add a SpringJoint to Springy and set its Connected Body property to the Anchor null in your scene

  • Set Gizmos for each of the null points and turn on Gizmos for runtime

  • Play with the numbers for Spring, Damper and drag until you get the motion you like and then you can turn off runtime Gizmo display

In my case, multiple SpringJoints are on separate bones of the parent object. I wish someone had spelled out use of SpringJoints for me before (the docs are horrible) and I find them quite useful... :)

Nov 08 '11 at 11:22 PM psdev
(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:

x147
x64
x11

asked: May 23 '11 at 03:27 AM

Seen: 2578 times

Last Updated: Nov 08 '11 at 11:24 PM