|
Rickk Turbo
Registered User
Join date: 8 Jan 2009
Posts: 17
|
03-08-2009 03:42
I've been experimenting with some movement scripts and one thing I could never figure out is how do I know which direction the avatar is facing 0 to 360 deg. I've tried various commands such as llGetLocalRot, llRot2Euler but the information I get from them I just don't understand. Basically I want to code a little compass HUD with a rotating needle so when I'm walking around I know the direction I am walking. I'm also coding a sprint HUD which makes the avatar run off in the direction it is facing but without knowing the angle I cannot calculate the next x/y co-ordinates. Any tips or coding suggestions would be most appreciated.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-08-2009 03:51
// forward direction vector (from an attachment) vector fwd = llRot2Fwd(llGetRot());
// Horizontal angle in radians, counter-clockwise from the x-axis/East float angle = llAtan2(fwd.y, fwd.x); if (angle < 0.0) { angle += TWO_PI; }
// ...in the unlikely case the avatar is facing straight up/down when sitting or in mouselook if (llFabs(fwd.z) > 0.999) { vector left = llRot2Left(llGetRot()); angle = llAtan2(-left.x, left.y); }
// ...in degrees float angleDeg = angle*RAD_TO_DEG;
|
|
Rickk Turbo
Registered User
Join date: 8 Jan 2009
Posts: 17
|
03-08-2009 09:20
Thanks for the code Hewee it works a treat, cheers 
|