Jump to content
  • Advertisement
Sign in to follow this  
cnboy0212

Verlet Intergration problem

This topic is 2181 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

What exactly is a timestep? let say i set the value of my acceleration to 2, i will expect the velocity of the my object (current position - previous position) to increase by 2 every second. Now if I run this code in 60fps, shouldn't my timestep be 1/60? However, after running it for 1 second(60 frames) i check the final velocity of the object, it's 0.032959. Am I thinking in the wrong direction?

Share this post


Link to post
Share on other sites
Advertisement
i think you are adding force(acceleration) or backuping position in wrong place
must be:
tmp=pos-bpos;
bpos=pos
pos+=tmp+acceleration; Edited by serumas

Share this post


Link to post
Share on other sites
so after playing around for a bit, it fixed the problem. The original formula i used that pos +(pos - prev_pos) + acceleration * timestep* timestep. I knew the problem is because of the timestep^2 in the end, so I removed 1 timestep at the end of the formula and it works just fine. But then I don't know if what i am doing is right or not. Since all the article I found about verlet integration used the formula above.

Share this post


Link to post
Share on other sites
i think best way is not to use time step.Lock your verlet update rate to constant 60 and
every timne you ad acceleration of force you just * 1/60
void add_acc(float a)
{
acceleration=a/60;
}

pos +=(pos - prev_pos) + acceleration;

Share this post


Link to post
Share on other sites
I am starting to think the original formula is correct. equation for calculating the displace is x = x0 + vi0*t + .5*a*t^2, i set x0 and vi0 = 0, then x = .5*a*t^2. since my a = 2, and t = 1, then x(displacement) should be 1 also. and if i used that formula i found from other article, and apply timestep of 1/60. after 1 second, the outcome is 1.00525(round off error i guess). It is close enough to the actually answer. but I still don't know why the velocity isn't 2 after one second. Physics is never my strong subject. At least i know it works correctly now. Maybe someone can explain? Thanks

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!