Jump to content
Sign in to follow this  
Master_Chief

direction of velocity script

Recommended Posts

I need an equation that will find the the direction in degrees that the object is travelling based on its velocity. I don't want the direction that the object itself is facing though. Any help? I am trying to make a slideslip script for a car.

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D

Maybe something like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_obj = _this select 0

_velX = velocity _obj select 0

_velY = velocity _obj select 1

_dir = _velY Atan2 _velX

hint format ["Direction of _obj: %1",_dir]

exit

no warranty

Share this post


Link to post
Share on other sites

Easy enough to do with some trig:

_vx = velocity _car select 0

_vy = velocity _car select 1

_dir = asin (_vy / sqrt(_vx^2 + _vy^2))

I might be mistaken on that, as I'm a bit tired atm.

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D

It is really the same, isn't it?

Share this post


Link to post
Share on other sites

Whoops, guess you posted while I was typing smile_o.gif. Yeah, mathematically it is the same, but [b.B.S.] T_D's solution is better, since it uses less commands and thus less cpu power.

Share this post


Link to post
Share on other sites

one minor thing, I think it's _velX Atan2 _velY. Also if you want to convert this to a normal 0-360 just do it like this:

Quote[/b] ]

_velX = (velocity _obj select 0)

_velY = (velocity _obj select 1)

_dir = _velX Atan2 _velY

?_dir < 0 : _dir = 360 + _dir

It really doesn't matter if you do that since the result is the same, just in positives, rather than negatives.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×