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.

Dark Physics & Dark A.I. & Dark Dynamix / Dark Physics- Finding the Speed of an Object

Author
Message
Darkowen
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 7th Feb 2009 18:07
I know i have to use the commands (phy get rigid body linear velocity x(x) and (phy get rigid body linear velocity z(x),
they work okay but what if i go at an angle?, so im slightly going up the x axis and the z.
what sum do i use to calculate the total speed using the 2 directions. I tried simply adding them, which worked okay but only for the first 90 degree's, after that it does not work because the velocity on the world goes in the minuses.
Sorry if its confusing, if theres a simplier way please tell me, maybe im just blind and im missing a key command or something but i cant see anything.

Thanks.
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 10th Feb 2009 22:58
( (linear velocity x) ^ 2 + (linear velocity y) ^ 2 + (linear velocity z) ^ 2 ) ^ (0.5)

is that what you want?

are the "linear velocity x" etc, the three vector components of the body's velocity?
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 10th Feb 2009 23:00
by the way, don't do the square root if you need to do it more than several times per loop. there are approximation functions for the SQRT function, or you can look at the range of values that get produced without SQRTing it and find an appropriate denominator to divide all the un-SQRTed speeds by for a real simple approximation

SQRT supposedly takes more CPU time than normal floating point operations
Darkowen
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 14th Feb 2009 13:58
Works perfectly Mate Thankyou!!
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 20th Feb 2009 20:38
^ (0.5) is just as slow as SQRT

Login to post a reply

Server time is: 2024-05-18 13:47:31
Your offset time is: 2024-05-18 13:47:31