Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Next Scripting Question

Cocoanut Koala
Coco's Cottages
Join date: 7 Feb 2005
Posts: 7,903
04-15-2005 23:03
All right. I have passed Stage 1. I have managed to get a script into an item. It was Strife's Sit Script, which I put into my pillow so I could sit cross-legged on it. It worked just fine, creating the sit cross-legged action. (The problem with the other script was syntax errors, which of course I have no knowledge to fix.)

However, although I could stand on my HEAD cross-legged on the pillow, or HANG cross-legged UNDER it, or lie on my SIDE cross-legged BESIDE it, or any number of variations that occured when I fiddled with the sit-rot thingie, as was suggested to me by the nice person who gave me this script, I couldn't sit on it properly.

I spent a few hours doing that. I made another pillow and tried it. These pillows were made from toruses. Then I decided to try something new, and took out a bed I made, which was made from boxes, and (successfully) put a free sleep script I had in my inventory into it. I tried it out, and looked very unique glued to the back of the bed's headboard in a sleep position. I fiddled with those rot numbers for a while, but didn't hit on any right combination there either.

Then I decided to see what these scripts would do on a plain square prim. The effect seemed to bear no resemblance to what one would normally expect from the action in either a bed or on a pillow when I tried them.

Next, I tried a small round object. (The button from the center of my pillow, actually.) What I discovered was that it made me sit BELOW it (the button) and to the FRONT of it. That seemed odd and pointless. No one is going to sit cross-legged on something 6 inches behind their head.

I concluded from tonight's gala of trial and error that these scripts - once put into the object - then must be manipulated somehow in order to move the avatar into the correct position. I tried it via every combination of the sit-rot - 0,0,90, 0,0,180.....360,360360 - as recommended by the person who gave me the script - but nothing worked.

A while later, through the depths of my headache, I remembered a Bingo pillow I had in my inventory which you could sit cross-legged on. I dragged it out, with the idea of taking the script from it and seeing if it worked any better, but I couldn't access the script to it.

So . . . I have run up against yet another arcane secret of scripting, and I just can't figure it out.

Now that I have the script I want into the item, how do I manipulate numbers in the script to sit in the proper place? Or to sleep in the proper place, or whatever? IS it a matter of manipulating numbers somehow? Or is it something else?

Thank you in advance for your help.

coco
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
04-15-2005 23:55
The secrets of llSitTarget: ;)

Okies, there are two "arguments" that llSitTarget takes, vector position, and rotation ... um, rotation :eek:

llSitTaget(<-0.5 ,0.0 ,1.0>, <0.0, 0.0, 0.0, 1.0>;);

So, the first three numbers in <> are the position.
If you rez a cube on the ground, it'll help visualise this.

The first number is going east and west along the cube. Lager than zero is going east from the center, and smaller than zero is going west.
The second number is north and south. Larger is north, smaller, south.
The third number is up and down. Larger than zero is moving up, smaller is moving down from the center of the cube.
In the example, the avatar would sit one meter above the cube, and half a meter west.

Now, the next four numbers are what's called a "quaternion". Now, if you're like me, you just said "HUH?"

Well, suffice it to say you don't really need to know much about them, save that they're how SL (and most other 3-d programs) represent an object's rotation.

Now, for most animations you do, you're not going to have to worry about this one. leaving it at no rotation (as in the example) will get you the results you want by-and-large. Not always, though. (ALso, instead of writing out the numbers, you can use the constant ZERO_ROTATION)

If you do need to rotate the avatar around, youll probably find it easier to use degrees around the three axes. So, lets say you had to rotate your cube 90 degrees around Y - that means the face that used to face east is now facing down. if you used the above sit target, the avatar would also be facing the ground.

So, you want to offset this. Rotating the avatar another 270 degrees around Y would bring it back to facing front. (270 + 90 = 360)

CODE
vector rot = <0.0, 270.0, 0.0>; // 270 degrees around Y
rotation sitrot = llEuler2Rot(rot * DEG_TO_RAD); // This converts the vector to a quaternion rotation.
llSitTarget(<-0.5, 0.0, 1.0>, sitrot); // Apply the sit target to the prim
Now, note that the avatar will now appear to be sitting one meter east of the prim, and half a meter up. Why? Becasue the prim is rotated, and the sit target coordinates are relative to the prim and it's rotation, and not to the world!
This can take a lil getting used to.

Okies. I hope that helps some. (I also hope I got that all right!) :D
_____________________
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-16-2005 04:52
There's a smart way to do the reverse rotations discussed in the final post of this recent thread.

But for the rotation if you work (as Strife's script did and Jillian has suggested) in degrees around X, Y and Z you can go back to the original prim, click edit>object and look at the numbers down in the bottom left corner for rotation. Put either their complement (the number that makes them add to 360) or the negative version of that number into the vector, in the order they're shown (so if it says X: 90 you'd use either -90 or 270) and that should have you sitting the right way.

Jillian is also (at least I'm pretty sure she is, I've not tried since 1.6) correct about the fact that your offset position rotates with the prim too. The easiest way I found to sort it out was again in edit mode, and stretch. You get the little red, green and blue boxes to drag on - they show you which axis is which for the prim you're looking at. So moving up (globally) might well be a negative x or y axis movement locally, depending on the rotations you put on the prim.

The other thing sounds like you've got a bed with a root prim that isn't the "bed" part - you will lie on the prim you put the script into, and if you didn't specifically choose the bed it would put it into the root prim, hence you lie on the headboard.

Cocoanut, feel free to try and IM me in world and if I'm not otherwise tied up I'll come and try and give you a hand.
Cocoanut Koala
Coco's Cottages
Join date: 7 Feb 2005
Posts: 7,903
04-16-2005 11:17
From: Eloise Pasteur
There's a smart way to do the reverse rotations discussed in the final post of this recent thread.

But for the rotation if you work (as Strife's script did and Jillian has suggested) in degrees around X, Y and Z you can go back to the original prim, click edit>object and look at the numbers down in the bottom left corner for rotation. Put either their complement (the number that makes them add to 360) or the negative version of that number into the vector, in the order they're shown (so if it says X: 90 you'd use either -90 or 270) and that should have you sitting the right way.

Jillian is also (at least I'm pretty sure she is, I've not tried since 1.6) correct about the fact that your offset position rotates with the prim too. The easiest way I found to sort it out was again in edit mode, and stretch. You get the little red, green and blue boxes to drag on - they show you which axis is which for the prim you're looking at. So moving up (globally) might well be a negative x or y axis movement locally, depending on the rotations you put on the prim.

The other thing sounds like you've got a bed with a root prim that isn't the "bed" part - you will lie on the prim you put the script into, and if you didn't specifically choose the bed it would put it into the root prim, hence you lie on the headboard.

Cocoanut, feel free to try and IM me in world and if I'm not otherwise tied up I'll come and try and give you a hand.

Yes, I was trying to work with that "complement" idea, just that stuck me intuitively as maybe what was needed, but I probably just didn't know how to go about it quite right. Tonight I will copy all this thread and work on it, and thanks also for the offer of help, I'll probably take you up on that when I fail at all this again, lol.

coco
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
04-16-2005 12:29
Unfortunately, I'm not really good at explaining this without a visual example - but I'll try anyway. :o

Step One: Make sure "use local axes" is set for your object.

This is the easiest way to spot errors. Certain prims rez at very strange rotations, so this will help you spot them. Alternately, you can check the rotation of the prim manually if you'd like.

Step Two: Use the local axes to set your sit target.

Sit targets are based on a prim's rotation. You should set the X/Y/Z position based on how the Red/Green/Blue arrows (respectively) display in this mode.

Step Three: Figuring out your sit rotation.

This is a bit more difficult. Remember that this rotation will also be based on the rotation of the prim, and the "default" rotation will point your avatar up on the Z (blue) axis.

Here are two scripts that should definitely come in handy. NOTE THE FIRST CHANGES THE SIT TARGET:

CODE
// Use this to base the target on world units
vector sit = <0,0,5>; // Relative Position vs. object in World Units
rotation rot = <0,0,0,1>; // Rotation of Object in World Units

default
{
state_entry()
{
rotation reverseSit = llGetRot();
reverseSit.s *= -1;
llSitTarget(sit * reverseSit,rot * reverseSit);
}
}


CODE
// Use this to base the target on relative position
vector sit = <5,5,5>; // Sit Position using object's local axes
rotation rot = <0,0,0,1>; // Final rotation modifier

default
{
state_entry()
{
// This really shouldn't work, but it does in LSL.
// Vector X and Vector Y both return as "zero vectors."
vector z = llVecNorm(sit);
vector x = z % (-1 * z);
vector y = z % x;
llSitTarget(sit,rot * llAxes2Rot(x,y,z));
}
}


Regardless, you'll want to "counter" the rotation of the root object first, then add in the desired rotation offset. The first script does that.

Step Four: Tweaking

This can easily be the most time-consuming step. Depending on the results, you'll probably need to tweak the position and rotation.

Hope that helps. :)
_____________________
---
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
04-16-2005 14:03
From: Cocoanut Koala
All right. I have passed Stage 1. I have managed to get a script into an item. It was Strife's Sit Script, which I put into my pillow so I could sit cross-legged on it. It worked just fine, creating the sit cross-legged action. (The problem with the other script was syntax errors, which of course I have no knowledge to fix.)

Interesting. I just cut and pasted the exact script I posted into a new "box" prim, and with no changes, and it worked right off.

I guess "help" is off coming off my agenda. Shame.

/esc
_____________________
http://slurl.com/secondlife/Together