Am i missing something from this trigger? (animation) - SLUniverse Forums
 
Navigation » SLUniverse Forums > Development Discussion and Support > Content Creation » Am i missing something from this trigger? (animation)


Content Creation Discuss building, scripting, and other forms of content creation for SL.

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2009, 11:45 AM   #1 (permalink)
Junior Member
 
Join Date: Nov 2009
Posts: 3
Red face Am i missing something from this trigger? (animation)

Okay i've made this bridge that rotates when you click on the root prim. It rotates fine but it's just way too fast and i can't figure out how to slow it down. I don't want it to pause ten seconds or so - it would just be nice if it would take more time getting from frame 0 to frame 1 and back.

I was told to change the llsleep(delay) to llsleep(number); but this just tells it to pause for however long i tell it to.
I've tried going through my rotation scripts and such to see if i can get parts out of it but the script seems to reject it with an 'error.' Any way here's the script:

float delay=0.3;
string status="off";
go(){
llMessageLinked(LINK_SET,2,"p1","");
llSleep(delay);
llMessageLinked(LINK_SET,2,"p0","");
}

default
{
on_rez(integer r){llResetScript();}
state_entry(){
llMessageLinked(LINK_SET,2,"p0",""); //Start is at frame 0
}

touch_start(integer total_number)
{if(status=="off"){
status="on";
llSetTimerEvent(delay*6);
}else{
status="off";
llSetTimerEvent(0);}
}
timer(){go();}
}


Any idea if i'm missing something or need to change something? Like i said - i'd like to be able to change the ammount of time that it takes to get from point A to point B and back again.

Thanks again for your help, i've been trying to work it out all day i even looked on Google for answers before asking here.
Vengeance_Ethaniel is offline   Reply With Quote
Old 11-05-2009, 07:20 PM   #2 (permalink)
Animates and Scripts
 
jeaniesing's Avatar
 
Join Date: Oct 2009
Location: rural northeast US
Posts: 33
My Mood:
SL Join Date: Sept 2006
This script only tells the other pieces what to do with llMessageLinked... perhaps post what the other script (in the pieces) says and someone could help?
__________________
jeaniesing is offline   Reply With Quote
1 User Agreed:
Old 11-06-2009, 02:40 AM   #3 (permalink)
Doing stuff
 
WarKirby Magojiro's Avatar
Happles!
 
Join Date: Sep 2007
Location: Glasgow, Scotland
Posts: 2,778
My Mood:
SLShopper Ads: 1
SL Join Date: 14/10/2006
Business: MagoTek Industries
Quote:
Originally Posted by Vengeance_Ethaniel View Post
it would just be nice if it would take more time getting from frame 0 to frame 1 and back.
That's your problem right there. An animation with 2 frames is more like just two static positions. I'm obviously aware that we're talking about object animation, but the same thing still applies.

luckily for you, this is one of my areas of expertise

The best way to do this. First of all, get your values for A and B. Position, rotation, and scale, if applicable.

The next thing you need to do is to interpolate them. This function suffices for position and rotation:

Code:
calc_pos_scale()
{
    positions = [];
    scales = [];
    posdifference = end_pos - begin_pos;
    scaledifference = end_scale - begin_scale;
    posincrement = posdifference / frames;
    scaleincrement = scaledifference / frames;
    for (i=0;i <= frames;i++)
    {
        positions += begin_pos + (posincrement*i);
        scales += begin_scale + (scaleincrement*i);
    }
}
Note that frames here is a global variable which you'll need to set. I find 20 frames looks plenty good enough for most animations, but bear in mind that you're going to have a delay of 0.2 secs per frame. Decide how long (in seconds) you want the animation to take, and divide that number by 0.2 to get the number of frames you'll need. 20 frames will generate a 4 second long animation.

For rotation, it's in two parts

Code:
calc_rot_frames()
{
    rotations = [];
    rotincrement = 1.0 / (float)frames;
    for (i=0;i <= frames;i++)
    {
        rotations += slerp( begin_rot, end_rot, (rotincrement*i) );
    }
}

rotation slerp( rotation a, rotation b, float f ) 
{
    float angleBetween = llAngleBetween(a, b);
    if ( angleBetween > PI )
        angleBetween = angleBetween - TWO_PI;
    return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
}
The slerp function is some fancy quaternion magic that I only sort of understand. it's the only part here that I didn't write from scratch. I translated it into LSL from a math website.

Once you run your data through these functions, you'll be left with 3 lists of positions, scales, and rotations. This processing will only need to be done once unless the start/end values change, so do it once and store the valuesfor reuse later.

You'll simply want to run through an llSetPrimitiveParams loop with the values from each element of the list, and the 0.2 inherent delay in the function will slow things down for you.

Lastly, bear in mind that this is all rather resource intensive. You're going to be sending an object update with every frame, and it can be a bit taxing on the sim. it's advised to only do in small parts as necessary, not something you should run constantly.
__________________
Wounds, both physical and mental, heal in time. bones reknit, therapy and drugs make you forget. Life goes on.
But nothing cures death. Please remember this.


Quote:
"Beware he who would deny you access to information, for in his heart he dreams
himself your master."
WarKirby Magojiro is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On