# pendulum / swing effect

This topic is 2474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, im trying to impliment a pendulum or swing effect and finding it a little difficult to get good results.

Ive googled and read and seen the forumulas to work out the period etc but im struggerling to convert these into comupter programming.

For now all im trying to do is a simple pendulum movement with dampening.

Anyone know how i could go about it?

Any language code is fine, im using C++ & lua.

Thanks
Andy

##### Share on other sites
I would try using the equations here http://en.wikipedia....m_(mathematics) for angular accleration (equation 1) and angular rate (equation 2) and then in an update loop do something like

 thetaDot = sqrt(2*g/l*(cos(theta) - cos(theta0))); thetaDoubleDot = -g*sin(theta)/l; theta += thetaDot*dt; thetaDot += thetaDoubleDot*dt; 

where "l" is the pendulum length, "g" is gravity and "dt" is your update time step.

And then you can just draw your sphere or whatever is on the pendulum based off of theta and the pendulum length "l"

To add it damping you could just add a drag term to thetaDot term and make it something like

 thetaDot = sqrt(2*g/l*(cos(theta) - cos(theta0))) - dragTerm; 

##### Share on other sites
Hi, thanks for that, thats sort of how i have been doing it and since got it more realistic.

Thanks
Andy