Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help w/ Vectors+Rotation...

Satemreh Suavage
Registered User
Join date: 18 Sep 2004
Posts: 10
11-15-2004 13:58
I'm havin' a horrible freaking time trying to do this.

I need to get the avatar's rotation around the Z axis (north, south... NOT up/down/roll) in degrees. That's it. I gotta be missing something.

thx
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
11-15-2004 14:43
if you're doing it in an attachment i think llGetRot() should do it. if it's with a sensor i think you need something like llDetectedRot(0) with the zero being changed for whichever avi you sensed and want to know the rotation of.

once you got that rotation in a variable like avi_rotation = llGetRot() or whichever you can get the Z rotation by using avi_rotation.z and the same works for X and Y.

edit: one other thing, i think you got the wrong axis. the Z axis is up/down. north/south is Y.
Satemreh Suavage
Registered User
Join date: 18 Sep 2004
Posts: 10
11-15-2004 17:40
rotation rot = llDetectedRot(0);
float temp = rot.y * RAD_TO_DEG;
vector movespot;

if (llVecDist(llGetPos(), llDetectedPos(0)) >= 3) {
llLookAt(llDetectedPos(0),1,1);

movespot.x = llCos(temp) * 2;
movespot.y = llSin(temp) * 2;
movespot.z = 2;

llMoveToTarget(llDetectedPos(0)+movespot,1);
}

=======================
That's the code I'm using atm. It can't be right... or at least doesn't appear to be with the way the thing is behaving. I want it to be 2 meters in front of the av, no matter where they're facing. ATM it's always going behind and a little to the left or right...

1. I need JUST the degrees for the rotation of the AV, from 0-360. I believe llDetectedRot() will give me anything from a negative value to 0, then to a positive max value. At least that's what it appears to be doing.
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
11-15-2004 18:09
From: Satemreh Suavage
rotation rot = llDetectedRot(0);
float temp = rot.y * RAD_TO_DEG;


You need to do a conversion from the rotation type, which is a quaternion, to an Euler representation. Like this:

CODE
vector eul = llRot2Euler( llDetectedRot(0) );
float temp = eul.y * RAD_TO_DEG;


The x, y, and z members of the rotation type DO NOT correspond to roll, pitch, and yaw.

Edit: Also note that llCos and llSin take an angle in radians, so you probably don't need the RAD_TO_DEG conversion.
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
11-15-2004 18:12
Jake is correct...

Don't think of the .x, .y, and .z components of a rotation as anything more than magic numbers. They don't map onto angles at all.

You need to do llRot2Euler() first.

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
11-15-2004 20:32
Satemreh, i can't read that code at all hehe... too mathy. but i did something kinda similar i think. if you always want something to be at the same point relative to the avi this is what i use....

vector offsest = <1,1,1>; // make this the offset from the avatar's position that you want.
vector target_pos = offset * llGetRot() + llGetPos();

that's if it's running in an attachment. if you're using sensors i think that second line would be something like...

vector target_pos = offset * llDetectedRot(0) + llDetectedPos(0);

then.....

llMoveToTarget(target_pos,1);

hope that helps.