# Movement Help

This topic is 5386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How can I move a object in 2D object space, and 3D object space using something like miles per hour?

##### Share on other sites
You have to figure out how many units your game points represent. In my game, 1.0 (point) represents an inch. So the number of points I move per millisecond represents the number of inches I move per millisecond. So if something is moving 1.0 point per millisecond, it is moving 1000 points per second, or 3,600,000 points per hour. Which is about 57 miles an hour [smile]

There are 1.0 of my points in an inch
There are 63360 inches in a mile
3,600,000 / 63360 = 56.818

There are no rules applied to what size you can use. You just need to decide on a scale and make all of your objects relative to that scale.

Is that what you meant?

##### Share on other sites
Actually that's what I'm using for my game also, 1.0 represents 1 inch. It's the easiest for me to understand since I can just use a ruler to measure anything.

So here is what I want to know.
Basically, using for an example, I want a box (later will be replaced with a car) to move in the 3D world at a constant speed like let's say 10mph or 55mph. Meaning no extra calculations for mass, speed up time, or friction. Just direction movement.

I know that I'm suppose to use this method to calculate the new position:
Position = Position + Velocity * Time

And that in velocity will also contain the angle of movement. But I need to know how to apply that constant none changing speed of like 55mph to it and also making sure that it keeps in sync with the game's FPS. This is what I need to know.

I have looked up dozens of examples on the internet, even RARS, but I can't find what I need. All of those examples deals with extra settings that I don't need and I can't figure out else wise.

So any of this information will be extremly useful and also I know for the other people wanting to know this as well.

##### Share on other sites
Well I figured it out.
I did some analysis and trial and error.

Basically I started a new Direct3D project to test out some methods for the movement, and here is what I used ...

speed = 10 inches per second

velocity.x = speed * cos(angle)
velocity.y = speed * sin(angle)

position.x = position.x + velocity.x * time
position.y = position.y + velocity.y * time

I tested out the object going 10 inches per second across a 120 inch polygon, and it successfully made the required seconds to travel the entire polygon.

Using squareroot(velocity.x * velocity.x + velocity.y * velocity.y) will return the number for the original '10 inches per second' from the velocity value.

For all of you who would like to know how I did the time part, here it is:

inside the program loop, this code is in the beginning:

time_difference = (current_time - last_time)
time_delta = (time_difference / 1000.0)
if time_delta > 0.05 then time_delta = 0.05
last_time = current_time

you will use time_delta for the 'time' value in the object's movement and it works perfectly.

if anyone sees any problems with this code, please let me know for I can correct any mistakes.

##### Share on other sites
Velocity = DesiredMPH * 0.0176

Position = Position + (Direction * Velocity * Time);

Where Direction is a vector, velocity and time are floats.

##### Share on other sites
You need to convert your desired speed, miles per hour, to inches per ms (millisecond, as that is most likely what your DeltaTime variable will be in).

So,
5280 feet in a mile * 12 inches in a foot = 63360 inches/hour
3600 seconds in an hour. 1000 ms in a second. 3600*1000 = 3,600,000.

63360 / 3,600,000 = 0.0176

Therefor you can scale mph value by that, to get the distance to move in your program per frame. (it's easier to show the conversion graphically, but ascii art is not my forte)

So if you want to move at 50mph:
50mph * 0.0176 = 0.88 inches (drawing units) / ms.
multiplying by DeltaTime (ms) leaves you with inches. So just increment position by that amount.

##### Share on other sites
Thanks about the measurement conversion, but that's the first thing I worked on before the actual movement, so I already know about it.
But thanks anyways.

Now it's time for me to work on steering and acceleration.

##### Share on other sites
Sorry - just being a bit nitpicky:
Quote:
 Original post by JiiaVelocity = DesiredMPH * 0.0176Position = Position + (Direction * Velocity * Time);Where Direction is a vector, velocity and time are floats.

vector velocity   // velocity is a vector quantity that contains direction and speedposition = position + (velocity * time)vector direction  // always normalizedscalar speed      // units/timeposition = position + (direction * speed * time)

NOTE: velocity = direction * speed, so nobody's wrong, I just wanted to clarify the terms for OP.

##### Share on other sites
Are you serious? Is it bad practice to call speed, "velocity"? Or to have velocity represented by a scaler?

I know a vector is supposed to represent direction * scaler. But it is not nearly as flexible as keeping them seperated. To find the direction, you have to renormalize, and to find the scaler, you have to compute the length.

Those two tasks make [ x,y,z * f ] look pretty easy [smile]

##### Share on other sites
Personally, I keep velocity seperated into direction and speed, for the reasons you mentioned. But most physics papers I've seen on the 'net don't, so I didn't want the OP or anybody else confused by the words used, as I was when I was learning how to do time-based movement.

• 18
• 18
• 11
• 21
• 16