Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

UpdateSitTarget() issues?

Arcane Clawtooth
5 By 5
Join date: 7 Jan 2008
Posts: 201
10-16-2008 01:02
Anyone using the UpdateSitTarget() function found in the LSL wiki? I've been using it for a while but am coming across a problem. The function is not rotating the avatar but is setting the rotation correctly for the prim. Any ideas what would cause this?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
10-16-2008 02:40
If I am right it is because the whole thing is a work around the fact that SitTarget can not be changed while sitting on it:) Instead of doing that the rotation and position parameters for the linked agent is modified
_____________________
From Studio Dora
Arcane Clawtooth
5 By 5
Join date: 7 Jan 2008
Posts: 201
10-16-2008 03:07
From: Dora Gustafson
If I am right it is because the whole thing is a work around the fact that SitTarget can not be changed while sitting on it:) Instead of doing that the rotation and position parameters for the linked agent is modified

Yes, that's how it's supposed to work, and how it has always worked in the past, but it's acting weird now. I thought maybe it was happening to other people as well.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-16-2008 22:07
From: Arcane Clawtooth
Anyone using the UpdateSitTarget() function found in the LSL wiki? I've been using it for a while but am coming across a problem. The function is not rotating the avatar but is setting the rotation correctly for the prim. Any ideas what would cause this?

It's not rotating the avatar anymore? Sounds like a simulator bug, it use to rotate the avatar. I'll take a look into it when I get time.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-16-2008 22:48
Here is a test script that I threw together. Just sit on the box and click it a few times. There may be a bit of drift in the values and the signs might flip, that is to be expected.

CODE

//Sets / Updates the sit target moving the avatar on it if necessary.
UpdateSitTarget(vector pos, rotation rot)
{//Using this while the object is moving may give unpredictable results.
llSitTarget(pos, rot);//Set the sit target
key user = llAvatarOnSitTarget();
if(user)//true if there is a user seated on the sittarget, if so update their position
{
vector size = llGetAgentSize(user);
if(size)//This tests to make sure the user really exists.
{
//We need to make the position and rotation local to the current prim
rotation localrot = ZERO_ROTATION;
vector localpos = ZERO_VECTOR;
if(llGetLinkNumber() > 1)//only need the local rot if it's not the root.
{
localrot = llGetLocalRot();
localpos = llGetLocalPos();
}
pos.z += 0.4;
integer linkNum = llGetNumberOfPrims();
do{
if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
{
llSetLinkPrimitiveParams(linkNum,
[PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos,
PRIM_ROTATION, rot * localrot / llGetRootRotation()]);
jump end;//cheaper but a tad slower then return
}
}while( --linkNum );
}
else
{//It is rare that the sit target will bork but it does happen, this can help to fix it.
llUnSit(user);
}
}
@end;
}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge

list GetSitTarget(integer prim, key av)
{//WARNING: llGetObjectDetails can introduce an error that goes as far as the 5th decimal place!
//This is highly unlikely to be ever noticed unless compounded over time.
//Do not use while moving (like in a moving vehicle)!!!
vector tp = llGetAgentSize(av);
if(tp)
{
if(prim == LINK_THIS)//llGetLinkKey doesn't like LINK_THIS
prim = llGetLinkNumber();

list details = [OBJECT_POS, OBJECT_ROT];
rotation f = llList2Rot(details = (llGetObjectDetails(llGetLinkKey(prim), details) + llGetObjectDetails(av, details)), 1);
rotation r = llList2Rot(details, 3) / f;

return [((llList2Vector(details, 2) - llList2Vector(details, 0)) / f) + (llRot2Up(r) * tp.z * 0.02638) - <0.0, 0.0, 0.4>, r];
}
return [];
}//Written by Strife Onizuka

rotation randomRot()
{//ported from QGLViewer
float seed = llFrand(1.0);
float r1 = llSqrt(1.0 - seed);
float r2 = llSqrt(seed);
float t1 = llFrand(TWO_PI);
float t2 = llFrand(TWO_PI);
return <llSin(t1)*r1, llCos(t1)*r1, llSin(t2)*r2, llCos(t2)*r2>;
}

go()
{
key user = llAvatarOnSitTarget();
if(user)
{
rotation r = randomRot();
vector p = <llFrand(5), 0, 0> * randomRot();
llSetRot(randomRot());
UpdateSitTarget(p, r);
llSleep(0.1);
llOwnerSay("Target: " + llList2CSV([p,r]) + "\nActual: " + llList2CSV(GetSitTarget(LINK_THIS, user)));
}
}

default
{
changed(integer change)
{
if(change & CHANGED_LINK)
{
go();
}
}
touch_start(integer a)
{
go();
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Arcane Clawtooth
5 By 5
Join date: 7 Jan 2008
Posts: 201
10-17-2008 01:16
From: Strife Onizuka
Here is a test script that I threw together. Just sit on the box and click it a few times. There may be a bit of drift in the values and the signs might flip, that is to be expected.

How strange, I wonder what I'm doing wrong then. I tested and it's getting passed the correct rotation on my script but it seems to use the previous rotation sent to it.

Thanks for checking it out, that narrows down my search a bit at least :)
Arcane Clawtooth
5 By 5
Join date: 7 Jan 2008
Posts: 201
10-17-2008 11:00
Ok, narrowed it down, it's only happening to that one animation, everything else works fine, weird.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-17-2008 16:43
From: Arcane Clawtooth
Ok, narrowed it down, it's only happening to that one animation, everything else works fine, weird.

Is it a user created animation (or one of the built in animations)?
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Arcane Clawtooth
5 By 5
Join date: 7 Jan 2008
Posts: 201
10-17-2008 23:58
From: Strife Onizuka
Is it a user created animation (or one of the built in animations)?

User created, it came with a multi-pose bed. I didn't like how the poses were handled (each animation in a separate part of the bed) so I used my own in-development multipose software and re-used the animations.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-18-2008 12:01
A viewer bug maybe? Bug report it on Jira?
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey