# spring and damping effect

## Recommended Posts

heron3d    132
Hi, I would like implement this spring and damping effect to my project. I looked into spring equations and Hooke's law (I'm in the exploratory phase) but the info I found doesn't really address the rotation of a vector. The quicktime shows a positional offset but also imagine a rotation influencing the sway and drag of the vector.

Can the vets out their point me in the right direction? What subjects should I google? Is there a good book you recommend? Do you have the working equation that achieves this? I'll take anything. Thanks.

Nikos

##### Share on other sites
kunos    2254
if you have a rigid body system in place, adding a spring/damper is just adding forces to a rigid body... the rotations will be handled by that automatically.

if you dont have a rigid body system in place... get one [img]http://public.gamedev.net/public/style_emoticons/default/tongue.gif[/img] .
You can code it yourself (good fun and learning experience) or just grab ODE, PhysX, Bullet, Havok and use theirs.

##### Share on other sites
heron3d    132
[quote name='kunos' timestamp='1311613805' post='4840059']
if you have a rigid body system in place, adding a spring/damper is just adding forces to a rigid body... the rotations will be handled by that automatically.

if you dont have a rigid body system in place... get one [img]http://public.gamedev.net/public/style_emoticons/default/tongue.gif[/img] .
You can code it yourself (good fun and learning experience) or just grab ODE, PhysX, Bullet, Havok and use theirs.
[/quote]

Using those engines is not an option All I have to work with are 2 vectors. Using these nominal vectors, I would like to calculate a third that represents those spring and drag forces. I thought about doing a simple weighted average of the two using their magnitudes as a weight but it seemed too much like a hack. So I'm appealing to the math gurus on this one. I'll take anything

##### Share on other sites
kunos    2254
that doesn't make any sense.

you need to formulate your problem properly or no guru is ever going to be able to help you.

##### Share on other sites
h4tt3n    1974
You could apply three one dimensional damped springs, one for each axis. This would give you the "swaying grass" effect you seem to be looking for. Also, this method does not requre a call to sqrt() or other cpu-expensive functions. For each axis, the force F would be F = -x*k - v*d, where x is displacement from rest position along given axis, k is spring stiffnes coefficient, v is velocity relative to rest position along given axis, and d is spring damping coefficient. Along the vertical axis, force would be F = -(x-xr)*k - v*d, where xr is rest distance above ground.

Alternatively, you could apply an angular or rotational spring, but this is considerably more complicated.

Cheers,
Mike

##### Share on other sites
heron3d    132
[quote name='h4tt3n' timestamp='1311619260' post='4840115']
You could apply three one dimensional damped springs, one for each axis. This would give you the "swaying grass" effect you seem to be looking for. Also, this method does not requre a call to sqrt() or other cpu-expensive functions. For each axis, the force F would be F = -x*k - v*d, where x is displacement from rest position along given axis, k is spring stiffnes coefficient, v is velocity relative to rest position along given axis, and d is spring damping coefficient. Along the vertical axis, force would be F = -(x-xr)*k - v*d, where xr is rest distance above ground.

Alternatively, you could apply an angular or rotational spring, but this is considerably more complicated.

Cheers,
Mike
[/quote]

That is exactly what I was looking for. Thanks Mike!

##### Share on other sites
heron3d    132
[quote name='h4tt3n' timestamp='1311619260' post='4840115']
You could apply three one dimensional damped springs, one for each axis. This would give you the "swaying grass" effect you seem to be looking for. Also, this method does not requre a call to sqrt() or other cpu-expensive functions. For each axis, the force F would be F = -x*k - v*d, where x is displacement from rest position along given axis, k is spring stiffnes coefficient, v is velocity relative to rest position along given axis, and d is spring damping coefficient. Along the vertical axis, force would be F = -(x-xr)*k - v*d, where xr is rest distance above ground.

Alternatively, you could apply an angular or rotational spring, but this is considerably more complicated.

Cheers,
Mike
[/quote]

BEAUTIFUL. thanks h4tt3n. works great!