- Home /
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!
Answer by Waz · May 23, 2011 at 04:25 AM
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.
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!
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 Is$$anonymous$$inematic 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... :)
Your answer
Follow this Question
Related Questions
How can I make a configurable joint behave like a spring joint? 0 Answers
How do I set up a configurable joint to Behave like a Spring Joint? 1 Answer
Difference between creating Configurable Joint in code and creating the same type of Joint in script 1 Answer
"bleeding" when using configurable joints 2 Answers
Violent shaking when using position drive in Configurable Joints 1 Answer