# Spring behaviour problem

EDIT: Please read the next post as it is more relevant by now.

Hi everyone

The updated spring joints in Unity 2.0 seems to behave differently than in Unity 1.6.

A bug in the physics engine or a misunderstanding of the Unity spring concept from my side? Please help me to clarify this. Yes, I already read the documentation on the springs a hundred times, but I might have missed an impotant fact.
I’ve tried to simplify the problem greatly.

Download and open the attached project or go through the following steps to recreate the setup:

THE SETUP:

1. Create two cubes and place one over the other with the space of a cube in between them
2 ) Apply a Rigid Body to the bottom cube, apply a Character Joint to the top cube and choose the bottom cube as Connected Body.
2. Select the Rigid Body of the top cube and set ‘Is Kinematic’ to true.

Set the Character Joint parameters like this (see attached image):
Anchor: 0, -0.5, 0
Axis: 0, -1, 0
Swing Axis: 0, 0, 1
Low Twist Limit: -1, ,0, 5, 0
High Twist Limit: 1, 0, 5, 0
Swing 1 Limit: 1, 0, 30, 0.5
Swing 2 Limit: 1, 0, 30, 0.5
Break Force: infinity
Break Torque: infinity

THE PROBLEM:
Try to pull the x and z handle on the bottom cube individually. If only one axis is pulled and dropped it starts to swing along that axis, energised by gravity, and eventually it goes to a halt. Great, but … if both axis are pulled the cube starts to swing in a circling movement and never seem to ease. Where did the friction go?

The Damper value doesn’t seem to have a influence on the circling, only on the individual axis.

Am I the only poor basted out here having trouble taming springs?
~ce

53042–1933–\$jointtest_983.zip (587 KB)

I solved part of the problem above by cranking up the Draft on the swinging Rigid Body, but now it looks so dull.

NEW QUESTION:
How to create a ‘really bouncy’ spring with Configurable Joint?

Documentation says:

Say I set Limit to zero because I want the joint to be pulled towards a specific point, like a natural spring. I crank up the Spring value and it looks like a spring al-right, but what if I want it to be more bouncy?

The Bouncyness force is never active because the borders are non-existant when the Limit is at zero. Or is it (?), because the higher I set Bouncyness, the less bouncy the joint becomes.

What is going on?

Any help is greatly appreciated.
~ce

Borders are not non-existent when the limit is set to zero. If limit is zero, the spring kicks in as soon as the object moves at all.

To make the spring more bouncy, keep the damper at zero, or very low.

Thanks Ulognep

Yes, the spring forces are active outside the borders set by Limit. When Limit is set to zero the object will always be outside the borders. It’s the bouncyness value I am referring to.

As I understand from the documentation and experimentation Bouncyness is applied within the borders.

What if zero Damping is not enough? When I test zero Damping the spring comes to halt after a short while, but I want it to bounce for a longer time – like the Spring Joint ( except I can’t use that, I need to customise it).

~ce

Ahh, no that’s not completely true. Bouncyness is not applied within the borders, it is applied at the point where the object reaches the border. If your borders are set to zero, you’re probably seeing some unusual behavior. In fact I wouldn’t be surprised if the bouncyness never kicks in in that case.

The best thing you can do is change the Target Position vector via a script. By moving the Target Position far away from the object’s current position, you can create some very “bouncy” effects with a powerful spring. Try experimenting with that and see if you can do what you want. If not, try changing the Target Velocity from scripting, but be aware that this works orthogonally from the Position Spring and Position Damper values. So you really want to use one or the other, as using both together would probably be unnecessarily complicated to do.

Yes, thats a more precise description.

I tested the idea and it seams to fulfil my most urgent needs. In the code below I only test the Y-axsis.

Sad that a script is needed to achieve a little bouncyness, but any work-around that can bring me beyond this tiring fight with springs is greatly appreciated. Thanks again Ulognep.

~ce

``````var workAroundBouncyness : float = 0.5; // {0, 1}

private var joint : ConfigurableJoint;
private var multConstant = 0.06;
private var maxDistance = 10;

function Start(){
joint = GetComponent( "ConfigurableJoint" );
}

function Update () {
// set spring force //
joint.yDrive.positionSpring = Mathf.Abs( joint.connectedBody.velocity.y * multConstant * workAroundBouncyness );

// set spring position //
if( joint.connectedBody.velocity.y != 0){
if ( joint.connectedBody.velocity.y < 0 ){
joint.targetPosition.y = joint.connectedBody.transform.localPosition.y - maxDistance;
} else {
joint.targetPosition.y = joint.connectedBody.transform.localPosition.y + maxDistance;
}
}
}
``````