Mass-Spring Damper System (AS3 Source Code)

Above is a little test app I’ve created to show the deliciousness of the mass-spring damper system (also known as a harmonic oscillator). Move your mouse anywhere inside the box and it’ll swing the ball accordingly to emulate real mass-spring physics.

In this post, I will briefly explain how you can add a mass-spring damper system into your own engine to simulate cool swinging action.

Source code (Actionscript 3.0): [ MassSpringDamper.as ]

A mass-spring damper is a system where there exists a mass attached at the end of  a spring. The forces that are involved in this system are the forces generated by compression/relaxation of the spring and, of course, gravity.

Using the F=ma approach, the acceleration gained from the mass-spring is:

a = ( -cv – k(x – xo) ) / m

Where m is mass of the object, v is velocity, (x-xo) is the distance between the end of spring and the mass, c is the friction constant and k is the spring constant.

In order to prevent your system from accumulating errors and blowing up, we will try to avoid using the classic forward euler integration method. Instead, we use the safer approach, the symplectic integration method. If you didn’t understand this last part, it’s okay. Just remember that systems like these can easily accumulate errors and just go completely nuts if you don’t take special care.

Anyhow, the source code is attached. Enjoy.


Subscribe to comments Posted on 01.23.10 to Game Development, How To by Eddie
Post Tags:

Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">


© Copyright 2010 Illogic Tree | "Modicus Remix" by Zidalgo | Log in