Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help! Trying to rotate linked avatar 90deg

sparky Kalinakov
Registered User
Join date: 1 Aug 2009
Posts: 4
10-05-2009 12:48
Ive created an object that an avatar sits on. Upon receiving a command VIA listen, the object sends the avatar to a position 5 meters to the east of the object and has the avatar start an animation. Unon receiving another comman, the avatar stops the animation, returns to the base position and plays the sit animation again.

All this works well currently.

The problem starts in that I also want the avatar to rotate 90 deg to its left as part of the move away, and rotate back when it returns to base.

I can get the rotation to work using llSetLinkPrimitiveParams() and a PRIM_ROTATION value. the problem I have is that I need to pick this object and move it often. I need to be able to set it down and have the Avatar rotate 90deg to ITS left and back regardless of the location of the object.

When I move the object, the rotation of the avatar seems to change axis. For example, If I rotate the object 90 deg to the left on the floor, the avatar, once sent to the offset position now rotates face-down 90 degrees.

I'm (obviously) fairly new at this. Why would the axis Im rotating on vary depending on the location of the root object?

Thanks,
-S.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-05-2009 12:57
My guess is that you're trying to modify the av's rotation, which is a quaternion, not a vector, so you're getting odd changes in orientation. Someone truly wise in such things (not me) will be able to see the error in your ways as soon as you post the part of the script that's giving you trouble. Meanwhile, take a careful read through http://wiki.secondlife.com/wiki/Rotation, where you can find answers to many questions about rotations.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
sparky Kalinakov
Registered User
Join date: 1 Aug 2009
Posts: 4
10-05-2009 19:32
Heres the relevant excerpts of the script. This runs in the poseball the avatar sits on. Without being able to directly query the avatar for its position and rotation, I have attempted to position the avatar relative to the poseball sit target.

Any ideas what Im doing wrong here?

Thanks,
-S.

vector sitpos = <.4,0,0>;
rotation sitrot = ZERO_ROTATION;
vector danceposition = <0,-.8,5>;
rotation dancerotation;
vector sitposition = <1.603,-.72,-.15>;
rotation sitrotation;

state_entry()
{
dancerotation = (llGetLocalRot() * llEuler2Rot(<0,90 * DEG_TO_RAD ,0>;)); // I think this would be 90 deg to the left of my current zero rotation in relation to the sit target
sitrotation = (llGetLocalRot()); // I think this would return the rotation of the sat upon object which should be equal to the rotation of an avatar on a ZERO_ROTATION sit target
llSitTarget(sitpos, sitrot);
llSetSitText("Sit Here!";);
}

//To move the avatar 5 meters away and rotate 90 degrees to the left
llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, danceposition, PRIM_ROTATION, dancerotation ]);

//To return the avatar to the sit target
llSetLinkPrimitiveParams(llGetNumberOfPrims(),[PRIM_POSITION, sitposition, PRIM_ROTATION, sitrotation ]);
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
10-05-2009 20:10
llSetPrimitiveParams([PRIM_ROTATION]) is borked, I'm afraid, and I think that's what you may be encountering. Take a look at http://jira.secondlife.com/browse/SVC-93 for the workround and see if that helps.
sparky Kalinakov
Registered User
Join date: 1 Aug 2009
Posts: 4
10-14-2009 19:19
Thanks for the tip! It took me a while to find the time to read the post and sort out how to implement it in my script.

I think I have gotten the drift, but my implementation is still not acting as expected. If I understand correctly, I need to divide my target rotation by llGetRootRotation() once to get to regional rotation or divide by llGetRootRotation() twice to get to local rotation.

At this point, my target rotation seems to be effected by the rotation of the original object. If I rotate the object the avatar sits on, the rotation the avatar moves to changes as well (but keeps the same axis now!).

Here is an excerpt of the current relevant part of my script. I have tried dividing by llGetRootRotation once and twice with identical results.

Maybe I've got a parenthesis out of place? Am I doing this correctly?

Thanks,
-S.



vector danceposition = <-1.7,5,.3>;
rotation dancerotation;
vector sitposition = <.3,-.095,.35>;
rotation sitrotation;



dancerotation = (((llGetLocalRot() * llEuler2Rot(<0,0,110 * DEG_TO_RAD>;))/llGetRootRotation())/llGetRootRotation());
sitrotation = (((llGetLocalRot() * llEuler2Rot(<0,0,20 * DEG_TO_RAD>;))/llGetRootRotation())/llGetRootRotation());



llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, danceposition, PRIM_ROTATION, dancerotation]);
llSetLinkPrimitiveParams(llGetNumberOfPrims(),[PRIM_POSITION, sitposition, PRIM_ROTATION, sitrotation]);
sparky Kalinakov
Registered User
Join date: 1 Aug 2009
Posts: 4
10-15-2009 08:43
Turns out I did it right. The above code works properly.

The problem I am having is that the script needs to reset upon a rotate inorder to read in the new position.

I thought I had achieved it using a tip from the LSL twiki. If I read it correctly, it said to test for (changed & CHANGE_TEXTURE) which would include the object being rotated. That is what is not working at this point. Here is the relevant portion of my code. I need to do two tests on a change, one for animation privelages, and one for the "did I just rotate" logic.

The if(change & CHANGED_LINK) clause works correctly. The if(change & CHANGED_TEXTURE) isnt firing when the object is rotated. What am I doing wrong?

thanks,
-S.

changed(integer change)
{
llOwnerSay("Changed";);
if(change & CHANGED_LINK)
{
llOwnerSay("Change is a link";);
key avataronsittarget = llAvatarOnSitTarget();
if(avataronsittarget != NULL_KEY)
{
llOwnerSay("Someone linked to me";);
if((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && llGetPermissionsKey() == avataronsittarget)
{
llOwnerSay("we have animation privelages";);
llStopAnimation("sit";);
llStartAnimation("chairsit";);
state onchair;
}
else
{
llOwnerSay("we dont have animation privelages - requesting them";);
llRequestPermissions(avataronsittarget, PERMISSION_TRIGGER_ANIMATION);
}
}
else
{
llOwnerSay("No one is linked to me - resetting script";);
llResetScript();
}
}
if(change & CHANGED_TEXTURE)
{llOwnerSay("Change is a texture or rotation - Resetting Script";);
llResetScript();
}
}