Change font size
It is currently Fri Aug 17, 2018 7:44 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: Script for a swing...
PostPosted: Tue Jan 26, 2010 7:17 pm 
Furious Typer

Joined: Wed May 20, 2009 9:36 am
Posts: 90
Any one have a script, that can be put into a swing? Basically if you click the swing, it will start swinging kinda thing... Been lookin' all over google, and no luck with one that will work...

Thanks in advance. :)


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Wed Jan 27, 2010 11:05 am 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Swing type scripts are a well kept secret in SL. So I think it would be unlikely to find easily. I know a couple of yrs ago I looked and could not find any, so I wrote my own and I can tell ya, while it should be simple, it isn't. Sorry, nothing I want to share either. No Offense.

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Wed Jan 27, 2010 9:31 pm 
Furious Typer

Joined: Wed May 20, 2009 9:36 am
Posts: 90
No worries WhiteStar, I totally understand it... I wrote one earlier, but MAN it's motion is choppy... Was just hoping to find a smoother one... I'll keep my eyes open...

But thanks for replying!


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Thu Jan 28, 2010 3:55 am 
OSG Elite

Joined: Wed Aug 05, 2009 1:59 am
Posts: 417
I got one, will post it here when i get in-world:)


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Thu Jan 28, 2010 8:21 am 

Joined: Sun Aug 02, 2009 10:24 am
Posts: 16
Hi,
This is what used for my hamock in SL, but have not tried it here in Osgrid :

{L_CODE}:
//The main script in root prim
////////////////////////////////

integer swing=FALSE;        //So it starts out NOT swinging
float time=0.4;             //Decreasing this (on it's own) makes the swing move FASTER and vice versa
integer steps=12;         
integer swingDegrees = 10;  //How far from the vertical the swing moves


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)
{
    llSetRot(x*Inverse(GetParentRot()));
}

default
{
    state_entry()
    {
       // normal = llRot2Euler(llGetRot());
        swingRad=DEG_TO_RAD*swingDegrees;
        llSetTouchText("Swing");
    }


    link_message(integer sender_num, integer num, string message, key id)
    {
       
        if(message == "swing")
        {
            normal = llRot2Euler(llGetRot());
            llSetTimerEvent(time);
            swing = TRUE;
        };
       
        if(message == "stop")
        {
            swing = FALSE;
        };               
    }
       

    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)>));
        } else
        {
            SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
            i++;
        }
    }
    moving_end()
    {
        normal=llRot2Euler(llGetRot());
    }
}

/////////////////////////////////////////////////////////////////////////////////////
//And in the the hamock (seat)


key agentKey = NULL_KEY;

integer permissionResult = FALSE;

string theAnim = "couchlay2 f2";//"Laying_Side_F";


key agent;

vector sittingPosition =<0.7,0.0,-0.9>;

rotation GetSitRot()
{
    vector eul = <220,45,62>;
    eul *= DEG_TO_RAD; //convert to radians
    rotation quat = llEuler2Rot(eul); //convert to quaternion
    return quat;
}


init()
{

    llSitTarget(sittingPosition,GetSitRot());
}

default
{
    state_entry()
    {
        init();
    }
   
    on_rez(integer times)
    {
        init();
    }

    changed(integer change) {
       

        if (change & CHANGED_LINK)
        {

            agent = llAvatarOnSitTarget();
            if ( agentKey == NULL_KEY && agent != NULL_KEY ) {
                agentKey = agent;
                llRequestPermissions(agentKey,PERMISSION_TRIGGER_ANIMATION);
            } else if ( agentKey != NULL_KEY && agent == NULL_KEY) {
                if (permissionResult) {
                    llStopAnimation(theAnim);
                    llMessageLinked(LINK_ROOT , 0, "stop",agent);
                }
                llResetScript();
            }
        }       
    }

   
    run_time_permissions(integer value) {
        if (value == PERMISSION_TRIGGER_ANIMATION) {
            permissionResult = TRUE;
            llStopAnimation("sit");
            llStartAnimation(theAnim);
            llMessageLinked(LINK_ROOT , 0, "swing",agent);
        }
    }
}


Last edited by Nebadon Izumi on Thu Jan 28, 2010 1:58 pm, edited 1 time in total.
put code in a code box for easier reading


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Thu Jan 28, 2010 6:25 pm 
Furious Typer

Joined: Wed May 20, 2009 9:36 am
Posts: 90
Thanks Billie! Sadly, it's a lil' choppy, and is the same one I'm using now... I DO have one, and will glady share it. It's very smooth, and does exactly what I want it to, the only problem is, I'm trying to get it to listen on a certain channel, to start and stop it from swinging, but not having much luck getting that to work... Funny tho, I've made every other script work in this manner... Thought I was gettin' prett good at it haha...

Any way, here's the un altered smooth swing script...

{L_CODE}:
float distance = 1.6;
float timetotake = 3.8;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;

startSwing()
{
    vector vDir;
   
    speed = distance / timetotake;

    llSetTimerEvent(timetotake);
    vDir = llRot2Up(llGetRot());
    llSetRot(stoprot);
    llTargetOmega( vDir, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
    vector vDir = llRot2Up(llGetRot());
   

    if( speed < 0 ) {
        llSetRot(backrot);
    } else {
        llSetRot(forerot);
    }
    llTargetOmega( vDir, speed, 1.0 );
    speed = 0 - speed;
}

integer swinging = 0;

default
{
    on_rez(integer sp)
    {
        llResetScript();
    }
       
    state_entry()
    {
        rotation rrot = llGetRot();
        vector vrot = llRot2Euler( rrot );
        stoprot = rrot;
        vrot.z += distance/2;
        backrot = llEuler2Rot( vrot );
        vrot.z -= distance;
        forerot = llEuler2Rot( vrot );

        llTargetOmega(<0,0,0>, 0, 0.0);
        swinging = 0;

    }
   
    timer()
    {
        swingchange();
    }

    touch_start(integer total_number)
    {
        if( swinging > 0 ) {
            swinging = 0;
            llSetTimerEvent(0.0);
            llTargetOmega(<0,0,0>, 0, 0.0 );
            llSetRot(stoprot);
            llTargetOmega(<0,0,0>, 0, 0.0 );
        } else {
            swinging = 1;
            startSwing();
        }
    }
   
    moving_end()
    {
        llSleep(2.0);
        llResetScript();
    }
}


If anyone wants to try to make it listen for certain messages to make it start and stop via another prim (remote) here's what has worked so many times in the past...

Trying to add this type of code to it...

{L_CODE}:
llListen(666610, "", NULL_KEY, "" );

{L_CODE}:
listen(integer number, string name, key id, string message)

{L_CODE}:
if(message=="swing")
        {
            swing=1;
        }
       
        {   if(message=="stop")
            swing=0;
           


Any ideas how to make that type system work on this script? It's just basic stuff really, but that's what I need, listen for a message on a certain channel to start/stop.

Anyway, have fun if you can use the script, may need adjusting as it's a script from SL. And thanks in advance if you can get it to do what I need!


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Thu Jan 28, 2010 6:46 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 392
Location: England UK
You nearly had it ;)

Your concept was right, but I basically took your concept then took the start and stop parts from the touch() event and placed them inside the listen event (no need to re-invent the wheel ;))
At the top you can simply change the listen channel (I set it to 1 for ease of testing), and if you want it to be operated by chat only then remove the entire touch() event.

{L_CODE}:
float distance = 1.6;
float timetotake = 3.8;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;
integer channel = 1; //change this for the channel you want it to listen on


startSwing()
{
    vector vDir;
   
    speed = distance / timetotake;

    llSetTimerEvent(timetotake);
    vDir = llRot2Up(llGetRot());
    llSetRot(stoprot);
    llTargetOmega( vDir, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
    vector vDir = llRot2Up(llGetRot());
   

    if( speed < 0 ) {
        llSetRot(backrot);
    } else {
        llSetRot(forerot);
    }
    llTargetOmega( vDir, speed, 1.0 );
    speed = 0 - speed;
}

integer swinging = 0;

default
{
    on_rez(integer sp)
    {
        llResetScript();
    }
       
    state_entry()
    {
        rotation rrot = llGetRot();
        vector vrot = llRot2Euler( rrot );
        stoprot = rrot;
        vrot.z += distance/2;
        backrot = llEuler2Rot( vrot );
        vrot.z -= distance;
        forerot = llEuler2Rot( vrot );

        llTargetOmega(<0,0,0>, 0, 0.0);
        swinging = 0;
        llListen(channel, "", NULL_KEY, "" );

    }
   
    timer()
    {
        swingchange();
    }

    touch_start(integer total_number)
    {
        if( swinging > 0 ) {
            swinging = 0;
            llSetTimerEvent(0.0);
            llTargetOmega(<0,0,0>, 0, 0.0 );
            llSetRot(stoprot);
            llTargetOmega(<0,0,0>, 0, 0.0 );
        } else {
            swinging = 1;
            startSwing();
        }
    }
   
    listen(integer number, string name, key id, string message)
    {
        if(message=="swing")
        {
            swinging = 1;
            startSwing();
        }
       
        if(message=="stop")
        {
            swinging = 0;
            llSetTimerEvent(0.0);
            llTargetOmega(<0,0,0>, 0, 0.0 );
            llSetRot(stoprot);
            llTargetOmega(<0,0,0>, 0, 0.0 );
        }
           
    }
   
   
    moving_end()
    {
        llSleep(2.0);
        llResetScript();
    }
}


ETA: hey, and Will, keep it up :) This is how I started out scripting, keep your sleeves rolled up and give it your best shot. things will start to drop into place soon :)

The LSL wiki is very much your friend too for reference. It will not only give you reference, but give you examples on how to use functions etc. http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Thu Jan 28, 2010 7:34 pm 
Furious Typer

Joined: Wed May 20, 2009 9:36 am
Posts: 90
OMG Adelle! Thanks! I see exactly what you did! And it makes sense to me too... kinda... HAHA

But above all, thanks for the encouraging words! I'm no guru by any means, but I think I'm grasping it alot better now that I've sorta seen how things work, and what makes them work...

Again, thanks for the help on that, and the sweet, encouraging words!

Will


Top
 Profile  
 
 Post subject: Re: Script for a swing...
PostPosted: Mon Mar 26, 2012 9:04 pm 
Furious Typer

Joined: Tue Mar 06, 2012 3:57 pm
Posts: 102
Hi All,
is it possible to change the float distance with an timer ?
after the script start the prim swing 10 sec with
distance = 1.6
than 10 sec with
distance = 2.0
than 10 sec with
distance = 2.5
than 10 sec with
distance = 3.0

and than stop it from alone

kind regards
Hans


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net