Jump to content

Swing Script


iCade
 Share

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

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

Recommended Posts

Hello there, I've been attempting to make a swing, however I cannot for the life of me wrap my head around the rotations.

Right now, the swing swings from left to right, instead of back to forth. I've been at this for an hour and still am no further. I am sure I am missing something fundamental, could anyone point me in the right direction? o.o

 

integer swing=FALSE;
float time=0.4;
integer steps=12;
integer swingDegrees = 10;

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

default 
{
    state_entry()
    { 
        normal = llRot2Euler(llGetRot());
        swingRad=DEG_TO_RAD*swingDegrees;
        llSetTouchText("Swing");
    }
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }

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

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4011 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...