Results 1 to 4 of 4

Thread: Body movement

  1. #1

    Body movement

    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
    Cheers

  2. #2

    Body movement

    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.
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  3. #3

    Body movement

    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:
    Code:
     vel &#58;= vel + acc*dt;
     pos &#58;= 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:
    Code:
    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
    Code:
    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.

  4. #4

    Body movement

    Quote Originally Posted by grudzio
    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!

    Quote Originally Posted by grudzio
    As for asymptotic approach try this
    Code:
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •