Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


A little lost...

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

Ok, before we start, its 3am here in england and i am on a caffine high, so if this question sounds stupid please do not flame me Now onto the question: Say i have these variables, Speed of object , Angle of object, Vector reperesetning object position (2d) and Time since last render: Is it possible to correctly predict how far the object should move? If not what more information would you say is required. Note: I am debuging \ testing a friends engine code (he deiceded to develop a small 2d engine) and he didnt think of framerate independent movement :O Anyway, any help is welcomed. [edited by - Zidane on November 8, 2003 10:25:51 PM]

Share this post

Link to post
Share on other sites

Position variables:
Take the objects start position, call it vStart,
the objects end position, call it vEnd,
the objects distance it will travel, called vTotal,
and the current position, vCurrent.

vTotal = vStart - vEnd; to find how far it moves

Timing variables:
You have the current time from GetTickCount(), call it tNow,
the time the last frame passed, call it tPast,
and elapsed time since last frame, call it tElapsed.

In your pre-frame computations :
1)See how much time in milliseconds has passed since last frame.

tElapsed = tNow - tPast;

2)Use this elapsed time as a measurement of how much of the distance has passed. If 50% of a second went by, the object should be 50% from the start.

vCurrent = tElapsed * vTotal;

You should be able to puzzle the rest out. Theres a bit more to it, but if you really grasp it, then it should be apparent to you how to use this. My advice would be to draw it out with a paper and pencil and get it to work with one axis first.


Share this post

Link to post
Share on other sites
Assuming that 0 degrees is up, and goes clockwise. Also that +itive x is horizontal to the right and +itive y is vertically upwards.

directionVector.x = speed * cos(angle);
directionVector.y = speed * sin(angle);

float dx = directionVector.x * timeDelta;
float dy = directionVector.y * timeDelta;

objectPosition.x += dx;
objectPosition.y += dy;

Hope that helps

Share this post

Link to post
Share on other sites
Thanks guys

Time to teach my friend that rushing code always ends up with something like this

Oh wait.. the caffine high just went, im off to bed

Night Night.

Share this post

Link to post
Share on other sites

  • 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!