Jump to content

Animation script: coordinate 2 poses with swing movement?


Emma Krokus
 Share

You are about to reply to a thread that has been inactive for 2853 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm not a great scripter - but have successfully modded and chopped bits of scripts...

Want to use 2 poses in a swing script I have. What I'd like is for one pose to animate the avi until it reaches the end of one swing movement, then change to the other pose...

This is the free script from Eloise Pasteur:

1 // Put this script in the pivot - the thing the swing swings around (it doesn't have to be a long rod). That needs to be the root of the prim set that actually swings - if you want/need a frame that needs to be a separate item. SL doesn't yet allow us hierarchical linking.
2
3 // Play with these bits - the orange comments tell you what's going on with each line I hope.
4
5 integer swing=FALSE; //So it starts out NOT swinging
6 float time=0.1; //Decreasing this (on it's own) makes the swing move FASTER and vice versa
7 integer steps=20; //The total number of steps in the swing's path. More steps=smoother swing. More steps (alone) means slower swing too - time for a complete swing cycle is steps * time (so 4.8 s with the default settings).
8 integer swingDegrees = 30; //How far from the vertical the swing moves
9
10 //If you play from here on down you might break the script. Do so at your own risk. There are no comments - just to encourage you NOT to play.
11
12 integer i=1;
13 float swingRad;
14 vector normal;
15
16 rotation Inverse(rotation r)
17 {
18 r.x = -r.x;
19 r.y = -r.y;
20 r.z = -r.z;
21 return r;
22 }
23 rotation GetParentRot()
24 {
25 return Inverse(llGetLocalRot())*llGetRot();
26 }
27 SetLocalRot(rotation x)
28 {
29 llSetRot(x*Inverse(GetParentRot()));
30 }
31
32 default
33 {
34 state_entry()
35 {
36 normal = llRot2Euler(llGetRot());
37 swingRad=DEG_TO_RAD*swingDegrees;
38 llSetTouchText("Swing");
39 }
40 touch_start(integer num)
41 {
42 if(swing)
43 {
44 swing=FALSE;
45 llSetTouchText("Swing");
46 }
47 else
48 {
49 swing=TRUE;
50 llSetTouchText("Stop swing");
51 llSetTimerEvent(time);
52 }
53 }
54 timer()
55 {
56 float stepOffset=(float)i/steps*TWO_PI;
57 if(i>steps) i=1;
58 if(swing==FALSE && (i==steps || i==steps/2))
59 {
60 llSetTimerEvent(0.0);
61 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
62 } else
63 {
64 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
65 i++;
66 }
67 }
68 moving_end()
69 {
70 normal=llRot2Euler(llGetRot());
71 }
72 }
 

My question is: is it possible to use this script with the 2 poses I have?

Where in the script would I insert the directions for the poses to play?

Thanks!

Emma :)

Link to comment
Share on other sites

Yes, you can do it.  I haven't tested the animation part of this in world, but I think it ought to work , for example.....

// Put this script in the pivot - the thing the swing swings around (it doesn't have to be a long rod). That needs to be the root of the prim set that actually swings - if you want/need a frame that needs to be a separate item. SL doesn't yet allow us hierarchical linking.// Play with these bits - the orange comments tell you what's going on with each line I hope.integer swing=FALSE; //So it starts out NOT swingingfloat time=0.1; //Decreasing this (on it's own) makes the swing move FASTER and vice versainteger steps=20; //The total number of steps in the swing's path. More steps=smoother swing. More steps (alone) means slower swing too - time for a complete swing cycle is steps * time (so 4.8 s with the default settings).integer swingDegrees = 30; //How far from the vertical the swing movesstring FrontAnim = "Anim A";string BackAnim = "Anim B";//If you play from here on down you might break the script. Do so at your own risk. There are no comments - just to encourage you NOT to play.integer Animate;integer i=1;float swingRad;vector normal;rotation Inverse(rotation r){    r.x = -r.x;    r.y = -r.y;    r.z = -r.z;    return r;}rotation GetParentRot(){    return Inverse(llGetLocalRot())*llGetRot();}SetLocalRot(rotation x){    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION,x*Inverse(GetParentRot())]);}default{    state_entry()    {        vector Size = llGetScale();        llSitTarget(<0.0,0.5*Size.y,0.0>,ZERO_ROTATION); //You'll need to adjust these        normal = llRot2Euler(llGetRot());        swingRad=DEG_TO_RAD*swingDegrees;        llSetTouchText("Swing");    }        changed (integer change)    {        if (change & CHANGED_LINK)        {            if (llAvatarOnSitTarget())            {                llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION);            }            else            {                Animate = FALSE;            }        }    }        run_time_permissions(integer perm)    {        if(perm & PERMISSION_TRIGGER_ANIMATION)        {            Animate = TRUE;        }    }            touch_start(integer num)    {        if(swing)        {            swing=FALSE;            llSetTouchText("Swing");        }        else        {            swing=TRUE;            llSetTouchText("Stop swing");            llSetTimerEvent(time);        }    }        timer()    {        float stepOffset=(float)i/steps*TWO_PI;        if(i>steps)        {            i=1;        }        if(swing==FALSE && (i==steps || i==steps/2))        {            llSetTimerEvent(0.0);            SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));            list Anims = llGetAnimationList(llAvatarOnSitTarget());            integer j = (Anims !=[]);            while(j)            {                --j;                llStopAnimation(llList2String(Anims,j));            }                    }        else        {            SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));            i++;        }        if (Animate)        {            if (i == steps/4)            {                llStopAnimation(FrontAnim);                llStartAnimation(BackAnim);            }            else if (i == 3*steps/4)            {                llStopAnimation(BackAnim);                llStartAnimation(FrontAnim);            }        }    }    moving_end()    {        normal=llRot2Euler(llGetRot());    }}

I'm assuming that the swing's Z-axis is horizontal -- it's rotating on it's Z-axis, in other words -- and that you cut it in half to make it pivot around one end of the half that's left.  You'd need to substitute your own animations for AnimA and AnimB, of course and, as noted, you'll need to fiddle with the sit target to get yourself to sit properly.

Having made this modification, just for fun, I ought to point out that Eloise wrote this in the days before llSetLinkPrimitiveParamsFast, and before we could address PRIM_ROT_LOCAL.  I changed her llSetRot to llSetLinkPrimitiveParamsFast, which speeeds things up dramatically, but I didn't bother to redo her math to deal with the local rotation directly.  It would be more elegant to do it, but it wouldn't change the appearance any.

I should also point out that if I were doiing this exercise from scratch (or almost scratch), I'd start with Dora Gustafson's lovely pendulum script instead.  It's based on llSetKeyframedMotion and uses the math to make it behave like a RL pendulum -- accelerating on the downswing and decellerating on the upswing, and adjusting its period to its length as a good pendulum should.  Adding your two animations to her script would be more of a pain than doing it with Eloise's, but it would make a very nice swing.

 ETA:   I have just tested this in world with animations, and it does work.

Link to comment
Share on other sites

Thank you Rolig - you've given me tons to think about :)))) 

I'll try the script as soon as I can get back into SL for longer than a couple minutes (laptop swallowed the cat me thinks).

And yes working with a swing which has the right axis and cut,

I'll take a look at Dora's script also - thank you for the link:).

 

Emma :)

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Hi Rolig :)

Was finally able to work on script:

The animations work perfectly in sync with the movement, ... BUT

The pivot prim turns from left to right, rather than forwards and backwards.

I've tried a number of things: I can get the avi to sit right for the movement, but then the pivot prim is in the wrong position for slicing...

I feel like maybe I'm missing something really obvious here?

Emma :)

 

 

Link to comment
Share on other sites

  • 3 years later...

Gosh, it's been 4 years since I looked at this script.  Like most scripts from ages ago, I can see things I would do differently if I were writing it today.  Still .....  If you want to be sure it always starts the same direction, just be sure that i == 1 when someone sits down.  The simplest way to do that is probably to reset it when the previous user stands up, in the changed event.  Like ...

            else            {
i = 1; Animate = FALSE; }

that.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2853 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...