Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Basic Local Rotation and Position

Logan Bauer
Inept Adept
Join date: 13 Jun 2004
Posts: 2,237
10-22-2005 09:53
<Please note my use of the term "pose" in the following will refer exclusively to animating child prims and have nothing to do with your avatar's dance-pose-type posing - sorry for any confusion>
<Also I'm terrible at explaining stuff like this, and not that great of a teacher, so please feel free to correct/elaborate on>

Fairly simple script, this is what I've been using to set up "animations" for moving vehicles and animals. This is done by recording different "poses" or key frames of animation for our object. I'd recommend naming each child-prim A,B,C, or 1,2,3 or something identifying each "piece". Keep in mind that the root prim, the last-selected prim of our link set which will appear highlighted in yellow instead of white (Edit:Hello 1.7, Ok, now blue :P) - should not be moving around and will be the "core" or "center" of our pet/vehicle/whatever you're animating. Each child-prim you position will be in relation to the root-prim - If you change the link order or location of the root prim you will have to redo and "refind" all your animations.

1. Create a linked object and put the "Get Local Rotation/Position Script" into each child-prim. (Remember to give everything a unique name) Don't need any scripts in the root prim, but the root prim will be our "center" and should not be moved while recording our poses.
2. Take a back-up copy of your object into your inventory.
3. Either use the "edit linked parts" checkbox, or unlink and relink your object (and remember to link using the same root prim, choose the same piece last while linking) - Position each child-prim into our "pose".
4. Here's where I use Notepad or Wordpad or some external text editor - I'm not sure why, you can just as easily use a notecard ingame. Click on each child prim in sequence (this is why it's helpful to name them all a,b,c,ect) - Then open the history log and capture all of the text they spit out. Should look like:

A: PRIM_POSITION,<143.22061, 102.92537, 194.64525>,PRIM_ROTATION,<0.05419, -0.24445, 0.20955, 0.94520>
B: PRIM_POSITION,<143.22061, 102.92537, 194.64525>,PRIM_ROTATION,<0.05419, -0.24445, 0.20955, 0.94520>
Ect, ect, depending on how many child-prims your animating.

Paste this ALL into our notecard. I usually type a "title/header", something like "POSE T1" and then paste it in a line or two beneath, because we're going to be recording each keyframe or "pose" and then pasting them back into our SetPos/Rot scripts.

5. Start back at step 3 - And using either your existing pose you just set up OR by pulling that backup back out of your inventory, make another "pose" and record it to our notecard.

6. Take all of our Get Pos/Rot scripts out of each child prim and replace them with the Set Pos/Rot script.

7. In each Set Pos/Rot script, we're going to paste back in what we have on our notecard. In the example Set Rot/Pos script here it's listening for 3 linkmessages, "t1", "t2", or "t3" and calling llSetPrimitiveParams accordingly. So look at our notecard, and from what we've recorded as POSE T1, POSE T2, ect - look for A: PRIM_POSITION,<143.22061, 102.92537, 194.64525>,PRIM_ROTATION,<0.05419, -0.24445, 0.20955, 0.94520>
and copy right after A: (or Object: or TailPieceA:, allll depending on how you named the child prims). Open our Set Pos/Rot script in our first child prim "a" and paste what we just copied at the first //******* PASTE "POSE" IN HERE ********
Then back on our notecard under POSE T2 find A: and copy that PRIM_POSITION line and paste it in to the next place you see //******* PASTE "POSE" IN HERE ********
Then take and copy POSE T3 from the notecard and paste it in the 3rd and final spot in our SetPos/Rot script.

8. And then, move on to B, or the next child-prim in your linkset and repeat the process. The result will be that when you put one main script into your object, and put in the line:
llMessageLinked(LINK_SET,0,"t1",NULL_KEY);
We will trigger the pose we recorded first onto the notecard and named "POSE T1"

And that's about it... If you have a vehicle you can make the main script send a single or a series of link-messages to trigger and "play back" each keyframe/pos. IF you're triggering a series of poses all at once, make sure you put llSleep(0.21); in between each place you're calling a new pose with llMessageLinked - this will help keep everything in synch and from "breaking up" by queueing and "piling up" calls for animations, since each time your child-prim moves IT will sleep for 0.2 seconds.

This is our Get Local Rotation/Position Script
CODE
default
{
touch_start(integer total_number)
{
llOwnerSay("PRIM_POSITION," +(string)llGetLocalPos()+ ",PRIM_ROTATION," +(string)llGetLocalRot());
}
}


This is our Set Local Rotation/Position Script
CODE
default
{

link_message(integer sender_num, integer num, string message, key id)
{
if(message=="t1")
{
llSetPrimitiveParams([

//******* PASTE "POSE" IN HERE ********

/ ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())

]);

}
if(message=="t2")
{
llSetPrimitiveParams([

//******* PASTE "POSE" IN HERE ********

/ ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())

]);

}
if(message=="t3")
{
llSetPrimitiveParams([

//******* PASTE "POSE" IN HERE ********

/ ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())

]);

}
}
}
Harke Hartnell
Registered User
Join date: 10 Nov 2005
Posts: 32
11-17-2005 11:16
LOVE your script, saved me alot of time on my animated vehicles. Attached are some pictures of what I've done with it so far, but it certainly won't end there!
They're previews of my new product hopefully to hit vehicle lots soon ;) Ehough shameless self-promotion, great work, and a wonderfully simple answer to an otherwise big headache!
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
11-17-2005 18:09
/54/a0/72320/1.html
_____________________
i've got nothing. ;)
Lumiere Noir
Ivory Tower Dweller
Join date: 25 Dec 2003
Posts: 212
A thousand humble thank yous
11-18-2005 21:54
Gosh Logan, thanks so much for this, I'm having a blast with it!

Lumi
_____________________
Want to learn to build? Visit the Ivory Tower Library of Primitives at Natoma (205, 170)

Have an Edifice Complex? Join the building group Edifice Rex, IM me by name!

PrimWiki! http://ivorytowerlibrary.com/primwiki
Ivory Tower Forums http://ivorytowerlibrary.com/forums
Natoma Picayune http://ivorytowerlibrary.com
Shippley Dittmann
Registered User
Join date: 30 Aug 2006
Posts: 13
SetRot
02-04-2007 21:17
default
{
state_entry()
{
llSay(0, "turning on!";);
llTargetOmega(<0,.5,1>,0.9,PI);
}
touch_start(integer total_number) // when i'm touched..
{
state off; // sets the script to a new "state" an starts running "state off"
}
} // this curly bracket ends the body default the default state.

state off // a second state besides "default"
{
state_entry()
{
llSay(0, "turning off!";);
llTargetOmega(<0,.5,1>,0.0,PI);
llSetRot(<0,0,0>;);
}
touch_start(integer total_number) // when i'm touched..
{
state default; // sets the script to a new "state" and starts running "state on"
}
} // this curly bracket ends the body of the off state.




what am I doing wrong? i am a total newb at LSL. sorry..