#### Archived

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.

## 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 on other sites
should be all you need. rotate the speed by the angle, multiply it by the time since last and += it to the current position.

##### Share on other sites
Totally!

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.

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.

-Jason

##### 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 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.

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 14
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009256
• ### Who's Online (See full list)

There are no registered users currently online

×