Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: 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
Original Thread
11-17-2005 18:09
/15/c8/66959/1.html
_____________________
i've got nothing. ;)
Lumiere Noir
Ivory Tower Dweller
Join date: 25 Dec 2003
Posts: 212
11-19-2005 10:57
I'm awfully thankful you posted this. I'm having a blast with it and it will help me a good deal to know how to do this reliably.

Thanks again!

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
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-19-2005 15:02
I've been working on a similar script for a good while now,

i think you can replace
CODE
/ ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())
with
* (llGetLocalRot() / llGetRot())
or
/ llGetRootRotation()
_____________________
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
Sabane Talamasca
Registered User
Join date: 25 Sep 2005
Posts: 56
12-31-2005 11:15
Looks great, hopefully i can get it to work for me...I was fine up until i made the 2nd clone and to where the prims will move, when i touch them they tell me they're are in the exact same positions as the earlier ones but clearly they are not.


ok figured out what i did wrong, but when completed i got my parent prim that sais "touched" lol must have messed something up.
Dylen Ratner
Registered User
Join date: 21 Mar 2006
Posts: 1
08-10-2006 10:20
awsome script i been looking for somthing to do this, my only Q and i know this is an old thread so plz excuse me for asking but im new to scripting i want to use this for an attachment but when i attach it it moves the prims in a funky way is there a way to use this as an attachment to and keep the prims moving the way i had them ? thx in advance
Shippley Dittmann
Registered User
Join date: 30 Aug 2006
Posts: 13
SetRot
02-04-2007 21:20
I need help with SetRot..

How do I set the rotation of an object to 0,0,0 ?


Here's what I have now..



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
Sterling Whitcroft
Registered User
Join date: 2 Jul 2006
Posts: 678
02-05-2007 17:12
No states within states?

then details on rotation are on the wiki:
http://rpgstats.com/wiki/index.php?title=Rotation
Fiona Branagh
... or her equivalent.
Join date: 1 Feb 2007
Posts: 156
02-20-2007 15:00
Any tips on animating prims in an attachment?

Currently the object works great until I wear it, and then the movements become wonky. I've been told this has to do with the inability to determine the avatar's rotation and use it properly as a root.

Thoughts?
Prophet Alexandre
Registered User
Join date: 27 Dec 2006
Posts: 8
need help with main script please
01-07-2008 05:43
this is a great script many many thanks, I am struggling though to make the 'Main script' you refer to that will trigger the series of poses i have recorded.

Please , please, please can anyone provide me with the script that will trigger the movement in the poses.

Thank you all :)