Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSitTarget v. llSetLinkPrimitiveParams

Cynebald Ceawlin
Scripting the night away
Join date: 15 Apr 2007
Posts: 30
12-30-2008 22:22
OK, I've gotten myself lost in about the 7th circle of rotational h*ll... :eek:

I would like to be able to adjust a sitting avi's position/rotation to match parameters specified to llSitTarget -- i.e. if I have

llSitTarget(sitPos, sitRot);

I would like to be able to do

vector aviLinkPos = <some fcn of sitPos>;
rotation aviLinkRot = <some other fcn of sitRot>;
llSetLinkPrimitiveParams(sittingAviLinkNumber, [PRIM_POSITION, aviLinkPos, PRIM_ROTATION, aviLinkRot]);

(The prim the avi is sitting on may or may not necessarily be the root prim...)

I have tried to figure out the proper transformations to apply to sitRot to get it to be what llSetLinkPrimitiveParams() needs to acheive the same avatar positioning as llSitTarget() gives, but my efforts have thus far been an epic fail. I've also tried searching this forum, read, re-read, re-re-read, and read again all the pages on LSL wiki I could find about rotations, and am STILL coming up blank. My apologies if there is already a thread in which this question is answered; if so I had as much success finding it as I have had getting my avi positioning to work...
_____________________
-----
Cynebald Ceawlin
Proprietor and Chief Scripter
The Mathom House:: Scripted Objects and What-Not
Nimue Isle (SLURL: http://slurl.com/secondlife/Nimue%20Isle/164/119/28)
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-30-2008 22:36
Check out the code snippets at:
http://wiki.secondlife.com/wiki/LlSitTarget
_____________________
http://slurl.com/secondlife/Together
Cynebald Ceawlin
Scripting the night away
Join date: 15 Apr 2007
Posts: 30
12-30-2008 22:46
Thanks Escort -- too rotationally befuddled to have looked on the actual SL wiki, I guess. :o Got hooked on the LSL wiki back when it had everything the SL wiki LSL portal had and more...

At any rate, quick glance sez that this should get me what I need.

Cyn
_____________________
-----
Cynebald Ceawlin
Proprietor and Chief Scripter
The Mathom House:: Scripted Objects and What-Not
Nimue Isle (SLURL: http://slurl.com/secondlife/Nimue%20Isle/164/119/28)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-31-2008 10:59
Unfortunately there is a bug in the sit position placement that makes it even a little more complex than that. I think if you look up "easy sit target positioner" or something like that (sorry I can't be more precise at the moment) you'll see there is actually an offset that needs to be applied in the prim's coordinate system AND a small offset that needs to be applied in the global coordinate system. It is REALLY screwy.

What I would really suggest is, if analytical positioning is desired, ALWAYS use llSetLinkPrimitiveParams(). Put the sit target CLOSE so the avatar doesn't jump all around when they first sit down, but just always call llSetLinkPrimitiveParams() immediately after the avatar sits. Something like:

CODE

vector SIT_POS = <1.0, 2.0, 3.0>; // or whatever
rotation SIT_ROT = <0.707107, 0.0, 0.0, 0.707107>; // or whatever

key sitter = NULL_KEY;

default
{
state_entry()
{
llSitTarget(SIT_POS, SIT_ROT);
}

changed(integer changes)
{
if (changes & CHANGED_LINK)
{
key newSitter = llAvatarOnSitTarget();
if (newSitter == NULL_KEY)
{
// Sitter may still be sitting, but not intersecting with sit target. If we wanted to track this, we'd
// have to search through the link set for sitter.
return;
}
if (newSitter != sitter)
{
// This bumps an old sitter if a new one sits down. We could do the opposite if really desired
// by searching for the old sitter in the link set instead.
if (sitter != NULL_KEY)
{
llUnSit(sitter);
}
sitter = newSitter;
}

vector localPos = llGetLocalPos();
rotation localRot = llGetLocalRot();
vector sitPosRoot = localPos+SIT_POS*localRot;
rotation sitRotRoot = SIT_ROT*localRot;

integer i = llGetNumberOfPrims();
while (i > 0 && llGetLinkKey(i) != sitter)
{
--i;
}
if (i <= 0)
{
// Not found?!
return;
}

llSetLinkPrimitiveParams(
i,
[ PRIM_POSITION, sitPosRoot, PRIM_ROTATION, sitRotRoot ]);
}
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-31-2008 17:28
and beware of the rotation oriented SVC-93 bug
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-31-2008 19:07
From: Void Singer
and beware of the rotation oriented SVC-93 bug

Oh yeah. Good point. I guess my example above didn't account for that. Exercise for the reader. ;)
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
12-31-2008 20:42
sls is more than 50% workarounds and less than 50% operations.