Jump to content
  • Advertisement
Sign in to follow this  
AndyGil

pendulum / swing effect

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!