Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

turret mis-aligns when angle is changed

Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
07-18-2006 08:08
I have a remote turret that only aims up and down. I would simply use SetRot with a preset Z angle but it needs to be able to be turned for positioning. The script I have so far works for aiming up/down but always resets the Z-angle to 0.
How do I get it to keep the Z-angle I turn it to manually when changing the Y-angle?

CODE
else if(message == "rot+10")
{
rotation yaw = llGetRot();
pitch = pitch - 10;
vector eul = <yaw.x,pitch,yaw.z>; //10 degrees around the whatever-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot(eul); //convert to quaternion
llSetRot(quat); //rotate the object
llOwnerSay((string)quat);
}


I thought using the '.z' part would guarantee that that specific value is used?
Would it be more efficient to supply a dialogue to set it to a preset angle on_rez?

- Jolan
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
07-18-2006 09:51
From: Jolan Nolan
CODE
else if(message == "rot+10")
{
rotation yaw = llGetRot();
vector eul = <yaw.x,pitch,yaw.z>; //10 degrees around the whatever-axis, in Euler form

Your 'yaw' variable is a quaternion, so it won't provide you directly with Euler system angle values, like you try to use it here. Something like
CODE

vector angle = llRot2Euler( llGetRot() );
angle -= <0.0, 10.0 * DEG_TO_RAD, 0.0>; // reduce current pitch by 10 degrees
llSetRot( llEuler2Rot( angle ));

... might work, but it's still a bit iffy. Would be better to build a temporary quaternion with rotation of 10 degrees around the Y-axis, then multiply current rotation by that, and use it as new rotation value ... it avoids the issues with Euler conversions this way.
Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
07-18-2006 22:33
Actually I decided to just leave it at 0 degrees for the yaw, onto collisions! :)

- Jolan