Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problem when rezzing a rotating object at certain height

Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
04-03-2008 17:28
hi,

I'm currently working on a script that allows an avatar to sit on an object, which carries this script. Once the avatar sits on it, it should run an animation and rez a permanently rotating object at a certain height (about the height of sitting avatar's hips).

Here is what i got so far:

//lsl

vector position = <0, 0, .7>; // Adjust position here
integer visible = TRUE;
string animation;

show()
{
visible = TRUE;
llSetAlpha(1, ALL_SIDES);
}

hide()
{
visible = FALSE;
llSetAlpha(0, ALL_SIDES);
}

default
{
on_rez(integer start)
{
llResetScript();
}

state_entry()
{

llSitTarget(position, ZERO_ROTATION);
animation = llGetInventoryName(INVENTORY_ANIMATION, 0);
}


changed(integer change)
{
if(change == CHANGED_LINK) {
key avatar = llAvatarOnSitTarget();
if(avatar != NULL_KEY)
{
llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION);

}
else if (llGetPermissionsKey() != NULL_KEY)
{
llStopAnimation(animation);
llWhisper(1111,"quit";);
show();
}
}
}

run_time_permissions(integer perm) {
if(perm == PERMISSION_TRIGGER_ANIMATION) {
llRezObject("spinning object", llGetPos() + <0, 0, 1.5>, ZERO_VECTOR, ZERO_ROTATION, 42);
llStopAnimation("sit";);
llStartAnimation(animation);

//missing code to rez spinning object at height of current avatar's hips at certain rotation, no matter what rotation this object (which holds scripts and animation) has.

hide();
}
}
}


//end lsl

This script animates the avatar, using the animation which is in this prim's inventory. Now I was trying to solve the rotation and "rez at certain height problem". I tried to get avatar's size and devide it by 2. This way I thought it was possible to detect the hips, as they are about in the middle of the avatar. Anyway, using llGetAgentSize didnt return a usable value (returned <0,0,0>;) since I used the LSL-WIKI example: vector size = llGetAgentSize(llDetectedKey(0));
The way my script is done I couldn't think of a way to get the avatar's key.

I guess my way to solve this is much too complicated. Got a certain feeling, there must be an easier way...

Any suggestions welcome!

Thanks in advance.
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
04-03-2008 18:25
Try this:

llRezObject("spinning object", llGetPos() + position * llGetRot(), ZERO_VECTOR, ZERO_ROTATION, 42);

My not so wild guess is that you can assume the hips of the AV are very close from the sit target, whatever animation is on.

With the line hereabove, the "spinning object" will be rezzed around sit position. If you want it to be parallel to the rezzer, change ZERO_ROTATION into llGetRot(); (assuming that the root prim of the "spinning object" is un-rotated).

Another solution would be to rez the "spinning object" at llGetPos() and make it use a very short range one-shot sensor (1 or 2 meters) to find the position and rotation of the nearest AV. Then you use llSetPrimitiveParams() to make it jump in position with the right rotation in one single instruction. That will work as well since the position a sensor reports is at hips height.
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
04-04-2008 05:31
thanks for your answer,


I managed to get correct height by detecting avatar's size and deviding it by 2.

here is the script again

//lsl

vector position = <0, 0, .7>; // Adjust position here
vector size;
integer visible = TRUE;
string animation;

show()
{
visible = TRUE;
llSetAlpha(1, ALL_SIDES);
}

hide()
{
visible = FALSE;
llSetAlpha(0, ALL_SIDES);
}

default
{
on_rez(integer start)
{
llResetScript();
}

state_entry()
{

llSitTarget(position, ZERO_ROTATION);
animation = llGetInventoryName(INVENTORY_ANIMATION, 0);
}


changed(integer change)
{
if(change == CHANGED_LINK) {
key avatar = llAvatarOnSitTarget();
size = llGetAgentSize(avatar); //detect avatar size
if(avatar != NULL_KEY)
{
llRequestPermissions(avatar,PERMISSION_TRIGGER_ANI MATION);

}
else if (llGetPermissionsKey() != NULL_KEY)
{
llStopAnimation(animation);
llWhisper(1111,"quit";);
show();
}
}
}

run_time_permissions(integer perm) {
if(perm == PERMISSION_TRIGGER_ANIMATION) {

float rezheight = (size.z/2); //thats about height of avatar's hips

llRezObject("spinning object", llGetPos() + <0,0,rezheight> * llGetRot(), ZERO_VECTOR, ZERO_ROTATION, 42);
llStopAnimation("sit";);
llStartAnimation(animation);


hide();
}
}
}


//end lsl

Now I get my spinning object to be rezzed at correct height, but still having problems with correct rotation. The object, which holds animation, scripts and a copy of the spinning object in its inventory, has a default rotation of 0,0,0. What I'm looking for is a way to rez my spinning object with a certain rotation no matter what rotation (on the z axis) the main object is set to. You can imagine the main object as a sphere, similar to a poseball.

Thanks
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-04-2008 08:57
The avatar's hips should always be at the sit target in the current prim's coordinate system. Except if the animation moves the hips; that could make it impossible to guess where the hips are (at any given time). Standard sit poses I believe move the hips "down" 0.4 meters though, so if the animation is designed to be a normal sit, you could use that. So something like this should work:

CODE

vector SIT_POS = ...;
rotation SIT_ROT = ...;
vector SIT_POSE_HIP_OFFSET = <0.0, 0.0, -0.4>;
rotation SIT_POSE_HIP_ROT = ZERO_ROTATION;
...
llSitTarget(SIT_POS, SIT_ROT);
...
vector avHipPosRelative = SIT_POS+SIT_POSE_HIP_OFFSET*SIT_POSE_HIP_ROT;
rotation avHipRotRelative = SIT_ROT*SIT_POSE_HIP_ROT;
rotation rot = llGetRot();
vector avHipPosGlobal = llGetPos()+avHipPosRelative*rot;
rotation avHipRotGlobal = avHipRotRelative*rot;