Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Easy Sit Target Positioner

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-06-2006 16:26
These two scripts let you very easily set sit target positions and rotations. You sit on a poseball, position yourself exactly where you want to be, and the sit target is calculated automatically for you.

This is an idea I had months ago, but I gave up because llSitTarget has a bug which makes exact calculation of target positions difficult. Thanks to the folks over at this thread and a little more detective work, we managed to come up with a way to work around the bug, and so I've produced the following scripts.

I'll be distributing this in-world via my store (for free), or you can construct it from the scripts below. Here's the instruction notecard:

From: someone

This system helps you easily calculate and set a sit target for any prim.

Written by Lex Neva. Please distribute willy-nilly.

Instructions:

1. Place the "sit target setter" script into a prim that will get the sit target.
2. Rez the Sit Target Helper.
3. Sit on the Sit Target Helper.
4. Move the Sit Target Helper so that you are positioned exactly where you want the sit target to be.
5. Click the prim you put the "sit target setter" script in.
6. Now the sit target is set. You can use the code the script outputs in a poseball script. Once the
sit target is set, you can remove the "sit target setter" script.

NOTE: To use a sit animation, place one copy in the helper and one copy in the base object. If the animation is no-copy, place the animation in the helper first while you position yourself, and then move it over to the base after you click it. Only the first animation in the inventory will be used.


MORE HELP: This is a completely free, open-source system. As such, I am not available to support it. Please feel free to ask for help on the forums.


Here's the "sit target setter" script:

CODE

// Sit target system by Lex Neva. Please distribute willy-nilly.

default
{
touch_start(integer total_number) {
llSensor("Sit Target Helper", NULL_KEY, ACTIVE|PASSIVE, 96, PI);
llSay(0, "Searching for Sit Target Helper...");
}

no_sensor() {
llSay(0, "Sit Target Helper not found. No sit target set.");
llSitTarget(ZERO_VECTOR, ZERO_ROTATION);
}

sensor(integer num) {
if (num > 1) {
llSay(0, "Multiple Sit Target Helpers found. Using closest helper.");
} else {
llSay(0, "Sit Target Helper found. Setting sit target.");
}

vector helper_pos = llDetectedPos(0);
rotation helper_rot = llDetectedRot(0);

vector my_pos = llGetPos();
rotation my_rot = llGetRot();

// calculate where the avatar actually is
vector avatar_pos = helper_pos + <0,0,1> * helper_rot; // due to helper's sit target
avatar_pos = avatar_pos - <0,0,0.186> + <0,0,0.4> * helper_rot; // correct for a bug in llSitTarget(), for helper sit target

vector target_pos = (avatar_pos - my_pos) / my_rot;
target_pos = target_pos + <0,0,0.186>/my_rot - <0,0,0.4>; // correct for the bug again, this time in my sit target
rotation target_rot = helper_rot / my_rot;

llSitTarget(target_pos, target_rot);
llSay(0, "llSitTarget(" + (string)target_pos + ", " + (string)target_rot + ");");
}

changed(integer change) {
if (llAvatarOnSitTarget() != NULL_KEY)
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
}

run_time_permissions(integer perm) {
string anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
if (anim != "") {
llStopAnimation("sit");
llStopAnimation("sit_generic");
llStopAnimation("sit_female");
llStartAnimation(anim);
}
}
}


And this script goes into a ball named "Sit Target Helper" (make sure you get that name right):

CODE

default
{
state_entry()
{
llSitTarget(<0,0,1>, ZERO_ROTATION);
}

changed(integer change) {
if (llAvatarOnSitTarget() != NULL_KEY)
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
}

run_time_permissions(integer perm) {
string anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
if (anim != "") {
llStopAnimation("sit");
llStopAnimation("sit_generic");
llStopAnimation("sit_female");
llStartAnimation(anim);
}
}
}


Enjoy!
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
12-09-2006 18:30
/15/c7/153278/1.html
_____________________
i've got nothing. ;)
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
12-09-2006 19:42
Very useful. I love it. Thank you very much. :)
From: Lex Neva
And this script goes into a ball named "Sit Target Helper" (make sure you get that name right):
What about using llSetObjectName("Sit Target Helper";); under the state_entry event?
_____________________
:) Seagel Neville :)
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-10-2006 08:50
Sure, I probably could have done that. In-world, I just pass it out as an object already set with the right name.
Rock Portello
Registered User
Join date: 2 Aug 2006
Posts: 1
12-10-2006 10:11
This is a godsend thanks so much
Robin Peel
Registered User
Join date: 8 Feb 2005
Posts: 163
12-10-2006 15:46
I have to say the same thing as everybody else. Thank you very much. I hated figuring out the sittarget for new seats. This is so cool. hehe, good job!
Jolan Nolan
wannabe
Join date: 12 Feb 2006
Posts: 243
12-11-2006 19:14
Why not simply move the poseball?
Mine turn transparent when you sit on them so you can't see them when in use. Then they become visible when you stand.

- Jolan
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
12-11-2006 19:56
hmm... This script helps you to an appropriate value of llSitTarget when you write another script. We never just presume that we use it for chairs, sofa and so on. For example, have you seen linked pose ball vehickles? Sometimes you have the case that you can't click on the target itself like a pose ball.
_____________________
:) Seagel Neville :)
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
12-11-2006 21:28
From: Jolan Nolan
Why not simply move the poseball?
Why are there poseballs at all? Doesn't it make more sense to just click on the chair and sit?

My suspicion is that a large part of the reason people build with poseballs is because it's so hard to get the pose right otherwise, in part because of the bug in llSitTarget Lex has got round. Why waste prims on pose balls?
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Piero Padar
#
Join date: 26 Aug 2005
Posts: 42
Nice!
12-12-2006 05:19
I did it with a totally different math (used that .4 with llRot2Up.....) and added all the frills like auto cleanup and sit camera view (with preview) for vehicles... did all math&scripting myself (I liked the challenge ~_^) so I'm not selling cheap... but I'm happy when I see collaborative open source! ^_^
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
12-12-2006 06:18
Poseballs are a waste of a prim...
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-12-2006 09:43
From: Piero Padar
I did it with a totally different math (used that .4 with llRot2Up.....) and added all the frills like auto cleanup and sit camera view (with preview) for vehicles... did all math&scripting myself (I liked the challenge ~_^) so I'm not selling cheap... but I'm happy when I see collaborative open source! ^_^


I think this does the same thing as your "0.4 with llRot2Up", because multiplying <0,0,0.4> * llGetRot() is the same thing as 0.4 * llRot2Up(llGetRot()). The only possible difference we have is my 0.186 figure, which I'm still not quite sure on. That number seems to work perfectly for me, so I think that makes it pretty likely that it's "right", but the folks in the thread I linked to above got a different number (another 0.4)...
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-12-2006 09:44
From: Jolan Nolan
Why not simply move the poseball?
Mine turn transparent when you sit on them so you can't see them when in use. Then they become visible when you stand.

- Jolan


The point of this is to avoid using an extra prim just for sitting. In lots of cases this isn't desirable. Sometimes (ie vehicles), another prim can't be spared. Sometimes it's preferable to avoid the extra script required for each poseball.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-12-2006 12:35
Great!

Please document the llSitTarget bug at http://lslwiki.com/lslwiki/wakka.php?wakka=llSitTarget, and please add this example to the Wiki example scripts!

Also, your "THIS THREAD" link doesn't point to the right place. There's no discussion there, just a link to this thread.

Thanks :)
Piero Padar
#
Join date: 26 Aug 2005
Posts: 42
12-12-2006 18:13
From: Lex Neva
multiplying <0,0,0.4> * llGetRot() is the same thing as 0.4 * llRot2Up(llGetRot())...


hmmm... not really... I didn't use llRot2Up that way... and that 0.186 seems to say there's something weird... but, as I said, I like collaborative OpenSource ^_^
I tested your script 3 times with weird rotations, and it seems to work.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-13-2006 10:32
From: Learjeff Innis
Great!

Please document the llSitTarget bug at http://lslwiki.com/lslwiki/wakka.php?wakka=llSitTarget, and please add this example to the Wiki example scripts!

Also, your "THIS THREAD" link doesn't point to the right place. There's no discussion there, just a link to this thread.

Thanks :)


Odd, the link works for me. Try this: /54/21/152434/1.html
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-13-2006 10:34
From: Piero Padar
hmmm... not really... I didn't use llRot2Up that way... and that 0.186 seems to say there's something weird... but, as I said, I like collaborative OpenSource ^_^
I tested your script 3 times with weird rotations, and it seems to work.


Well, in that case, I'm not sure what you mean. 0.186 does sound "weird", yes, but it's very close to 0.1875, which is an even 16th, so who knows. It could also be a rounded irrational number, or a sine of something, for all we know.
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-13-2006 11:02
The variance is inversely related to the avatar's geometry, i.e., the smaller the avatar, the larger the offset. You can see this most when tinies sit on things.

It's constant for a particular avatar, and it's rotated by the sit rotation around an axis at <0,0,0.4> from the prim's axis, rotated by the prim's rotation.

~Boss
Piero Padar
#
Join date: 26 Aug 2005
Posts: 42
12-13-2006 12:31
From: Boss Spectre
The variance is inversely related to the avatar's geometry, i.e., the smaller the avatar, the larger the offset. You can see this most when tinies sit on things.

It's constant for a particular avatar, and it's rotated by the sit rotation around an axis at <0,0,0.4> from the prim's axis, rotated by the prim's rotation.

~Boss


Well it seems I found the Holy Grail :D cause I tested it with tinies&talls and don't see any offset difference.
Thanks Boss: I bought your primsitter some days ago; it inspired me and made me take the challenge of makin one myself ^_^
I'm sad cuz I can't opensource the math after all the work I did to make a commercial product... :(
...but I gave some hint in previous posts... ~_^

~Piero
Piero Padar
#
Join date: 26 Aug 2005
Posts: 42
Did I find the Holy Grail?
12-13-2006 12:31
From: Boss Spectre
The variance is inversely related to the avatar's geometry, i.e., the smaller the avatar, the larger the offset. You can see this most when tinies sit on things.

It's constant for a particular avatar, and it's rotated by the sit rotation around an axis at <0,0,0.4> from the prim's axis, rotated by the prim's rotation.

~Boss


Well it seems I found the Holy Grail :D cause I tested it with tinies&talls and didn't see any offset difference.
Thanks Boss: I bought your primsitter some days ago; it inspired me and made me take the challenge of makin one myself ^_^
I'm sad cuz I can't opensource the math after all the work I did to make a commercial product... :(
...but I gave some hint in previous posts... ~_^

~Piero
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
12-13-2006 19:42
From: Piero Padar
Well it seems I found the Holy Grail :D cause I tested it with tinies&talls and didn't see any offset difference.

There does appear to be a difference but it's very tiny (bad pun not intended) ... 1-2 cm.

That said, the size of variance i could measure was in range 3-5 cm rather than 18+ cm used in the OP script... no idea what would be causing such difference, i've used shapes ranging from tiny AVs to regular SL size ones o.O;
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-13-2006 20:13
Thanks Lex, the link works fine now for me too, so it was some kind of temporary thing.
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
12-13-2006 20:57
Curiously enough, the small variation nonwithstanding a simplified version of this code appear to work reliably.. and no, i have no idea why :s
CODE

// script for the prim to adjust. helper is set up with sit at <0, 0, 0.001>, ZERO_ROTATION

default {

touch_start( integer Contacts ) {

llSensor( "sit_target_helper", NULL_KEY, PASSIVE | ACTIVE, 10.0, PI );
}

no_sensor() { llOwnerSay( "... no sit target helper found." ); }

sensor( integer Contacts ) {

vector target_pos = llDetectedPos(0);
rotation target_rot = llDetectedRot(0);

target_pos += 0.4 * llRot2Up( target_rot );

rotation sit_rot = llGetRot();
target_pos -= 0.4 * llRot2Up( sit_rot );
target_pos -= llGetPos();

llSitTarget( target_pos / sit_rot, target_rot / sit_rot );
}
}
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-14-2006 10:00
From: Boss Spectre
The variance is inversely related to the avatar's geometry, i.e., the smaller the avatar, the larger the offset. You can see this most when tinies sit on things.

It's constant for a particular avatar, and it's rotated by the sit rotation around an axis at <0,0,0.4> from the prim's axis, rotated by the prim's rotation.

~Boss


I'm fairly certain this isn't the case. I tested this while wearing avatar shapes of varying sizes, and it always landed me on exactly the same spot.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
12-14-2006 10:02
From: Joannah Cramer
There does appear to be a difference but it's very tiny (bad pun not intended) ... 1-2 cm.

That said, the size of variance i could measure was in range 3-5 cm rather than 18+ cm used in the OP script... no idea what would be causing such difference, i've used shapes ranging from tiny AVs to regular SL size ones o.O;


Now that I think about this, I believe I did see a variance of a few cm like that as I changed my av size, as well. It could be that I didn't get my magic numbers exactly right, or it could be that sit targets do vary with av size, but only very slightly. Either way, I think it's small enough that the difference in the sit position is negligible for most purposes.
1 2 3 4