Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Converting an objects ingame speed to mph?

Author
Message
z i l c h vortex
19
Years of Service
User Offline
Joined: 20th Feb 2007
Location: united kingdom
Posted: 24th May 2011 23:35
I've got an object moving around in this game i'm working on. Doe's anybody know how to roughly work out how fast an object is moving in mph?

Thank you.
Josh

life is short but so am i
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th May 2011 00:02 Edited at: 25th May 2011 00:04
First you define how many units will make up one mile (UnitsPerMile#).

Then you can roughly determine an objects speed by using:

START LOOP
...
x# = OldX# - object position x(obj)
y# = OldY# - object position y(obj)
z# = OldZ# - object position z(obj)
Speed# = sqrt(x#*x# + y#*y# + z#*z#) / UnitsPerMile#
OldX# = object position x(obj)
OldY# = object position y(obj)
OldZ# = object position z(obj)
...
END LOOP

[edit] There are variations of course. You can leave out the y# (-> sqrt(x#*x# + z#*z#) / UnitsPerMile#), or you can use vectors to make it faster, etc. But I think this is the most basic method.

Good luck!
Sven B

z i l c h vortex
19
Years of Service
User Offline
Joined: 20th Feb 2007
Location: united kingdom
Posted: 25th May 2011 00:27
I used this on just my y axis but it doesn't work properly :/ can you use this just for the y axis?

Thank you for your help much appreciated Sven B.

life is short but so am i
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2011 04:50
He shouldn't even need to do that sqrt operation as he should already know the amount the object moves each loop.

Login to post a reply

Server time is: 2026-07-11 04:24:17
Your offset time is: 2026-07-11 04:24:17