PDA

View Full Version : Body movement



IlovePascal
12-12-2006, 12:16 AM
Hey! I can see this forum is stagnating... so let's revive it!

Here is my problem:

When I move a body (particle, object, whatever), I always add the acceleration to the velocity and the velocity to the position of the object. That's basic physics, ryt?

However, when Im tryin to make it approach an axis, it goes into simple harmonic motion. I know that's due to my environment's lack of friction.

So I went through my physics books and found a lot of formulae linking displacement and time with damping, but my problem is that I don't move my particles depending on time, but depending on their distance to where I want to move them to.

Im sure most of you have come across this, so I was wondering if you could help me out.

What Im looking for is 2 things: a way to create damped harmonic motion, and a way to create a hyperbola-type motion, i.e. smoothly approching an asymptote without crossing it.

Thanks for your help :P
Cheers ;)

tanffn
12-12-2006, 08:40 AM
Not really helping.. but I done so in Catapults using time based (N frames, where N is a constant).
I don't think you can create a hyperbola-type motion without the time factor.. maybe we can fake something out if you give me more info regarding the environment and draw me the motion you want to create.

grudzio
12-12-2006, 12:13 PM
but my problem is that I don't move my particles depending on time, but depending on their distance to where I want to move them to.

Actually your movement is time dependent. You do something like this:


vel := vel + acc*dt;
pos := pos + vel*dt;

where dt is time step. You just set dt to one. If you keep dt constant you have frame dependent movement - the faste CPU you have, the faster your objects will move. To make it frame independent so it will move at same speed on slow and fast machines use dt = time_elapsed / 1000 where time_elapsed is time difference of last and curren frame (in miliseconds).

But to anwser your questions. This oscillating behaviour does it happen when you are almost at the destination? you use code to detect if you have reached the destination like this:


if &#40;Abs&#40;x-destx&#41; < EPS&#41; and &#40;y-desty&#41; < EPS&#41; then
StopMoving
else
KeepMoving;

The oscillations will appear if the EPS constant is to small.

As for asymptotic approach try this


d &#58;= sqrt&#40;pos*pos-dest*dest&#41;; //d - distance to destination
pos &#58;= pos + 0.5*d*dt; //dt - timestep


Hope it will help you.

IlovePascal
13-12-2006, 09:12 PM
But to anwser your questions. This oscillating behaviour does it happen when you are almost at the destination? you use code to detect if you have reached the destination like this:

Code:
if (Abs(x-destx) < EPS) and (y-desty) < EPS) then
StopMoving
else
KeepMoving;

The oscillations will appear if the EPS constant is to small.


I see, yes. Well I think thats a great idea. Ill make it accelerate when further away than EPS and decelerate when inside that area. Thanks for the idea! :D



As for asymptotic approach try this


d &#58;= sqrt&#40;pos*pos-dest*dest&#41;; //d - distance to destination
pos &#58;= pos + 0.5*d*dt; //dt - timestep


Hope it will help you.

How did I not think about that! lol! That's more an exponential decay but it will do just fine! Thank you. :wink: