Jump to content

Rocking Chair Resets It's Position


Kallie Barrowstone
 Share

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

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

Recommended Posts

I know that there has got to be a simple fix for this (at least I hope!) Below is the script I'm using for my rocking chair. My problem is that when I turn the chair to face another direction it will reset itself to the original position when you click to begin rocking. I would love to be able to turn the chair to face any direction and have it rock as expected when clicked. 

I'm not even partially lsl literate, so any help from those more knowledgable than me is greatly appreciated!

 

integer swing=FALSE;        //So it starts out NOT swinging
float time=0.01;             //Decreasing this (on it's own) makes the swing move FASTER and vice versa
integer steps=12;           //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 = 10;  //How far from the vertical the swing moves

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

default 
{
    state_entry()
    { 
        normal = llRot2Euler(llGetRot());
        swingRad=DEG_TO_RAD*swingDegrees;
        llSetTouchText("Rock");
    }
    touch_start(integer num)
    {
        if(swing)
        {
            swing=FALSE;
            llSetTouchText("Rock");
        }
        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 + swingRad*llSin(stepOffset), normal.y, normal.z>));
        } else
        {
            SetLocalRot(llEuler2Rot(<normal.x + swingRad*llSin(stepOffset), normal.y, normal.z>));
            i++;
        }
    }
    moving_end()
    {
        normal=llRot2Euler(llGetRot());
    }
}

 

Link to comment
Share on other sites

It will probably help if you reset the script after you move the chair but before you start rocking

Moving_end should set 'normal' but you can't always rely on that event firing after a move

:smileysurprised::):smileyvery-happy:

OH! Wrong forum. The question should have been in LSL Scripting

Link to comment
Share on other sites

Nope, I have it in a sphere that is situated under the seat of the chair, and I have that prim set as the root. 

 

Making it a child prim doesn't allow me to click the chair to begin rocking. I was under the impression that the script had to be in the root prim so that it can rock all other child prims?

Link to comment
Share on other sites

It makes no sense to use llGetLocalRot() in the root prim, that's why I objected
When you do then the function GetParentRoot() will always return the ZERO_ROTATION
and the function: SetLocalRot(rotation z) will set the rotation to z

integer swing=FALSE;        //So it starts out NOT swingingfloat time=0.01;             //Decreasing this (on it's own) makes the swing move FASTER and vice versainteger steps=12;           //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 = 10;  //How far from the vertical the swing moves//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 i=1;float swingRad;vector normal;}SetLocalRot(rotation z){    llSetRot( z*llGetRot());}default{    state_entry()    {        normal = llRot2Euler(llGetRot());        swingRad=DEG_TO_RAD*swingDegrees;        llSetTouchText("Rock");    }    touch_start(integer num)    {        if(swing)        {            swing=FALSE;            llSetTouchText("Rock");        }        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 + swingRad*llSin(stepOffset), normal.y, normal.z>));        } else        {            SetLocalRot(llEuler2Rot(<normal.x + swingRad*llSin(stepOffset), normal.y, normal.z>));            i++;        }    }    moving_end()    {        normal=llRot2Euler(llGetRot());    }} 

 

This modified script does very much what you want
It doesn't compensate for child rotated against the root, why would you want a script to do that?
It is much, much easier to change the linkset
I noticed the script not always stop the chair in neutral, but that's another problem and outside the scope of the question

 

Link to comment
Share on other sites

the main thing is to rotate it relative to its starting rotation

i made some mods to your script as an example of how it can be done

can use or not as you like. can mod/do whatever you like as well

+

edit: I actual made 2 mistakes in the script. Is supposed to be a swing / rocker / pendulum thingy. Should have used Cos() instead of Sin. And I forgot some brackets. So i changed it. Should be ok now I hope (:

 

float   time  = 0.01;  // Decreasing this (on it's own) makes the swing move FASTER and vice versainteger steps = 12;    // The total number of steps in the swing's path. More steps = smoother                       // More steps (alone) means slower too - time for a complete cycle is steps * timefloat degrees = 10.0;  // How far from the vertical the swing moves// best to not change theseinteger swing = FALSE; // So it starts out NOT swinginginteger stop = TRUE;   // Stops multi touches from wreck the start rotationinteger step = 1;      // From 1 to steps and repeat until timefloat radians;         // Conversion of degrees to radiansvector arc;            // For the swing calcsrotation startrot;     // save start rotation and orient off thatdefault {    state_entry()    {         radians = DEG_TO_RAD * degrees;        llSetTouchText("Rock");    }    touch_start(integer num)    {        if ((swing = !swing) && stop)        {            startrot = llGetRot();            arc = llRot2Euler(startrot);            llSetTouchText("Stop");            llSetTimerEvent(time);        }    }       timer()    {        stop = !swing && (step == steps);        if (!stop)        {            float offset = radians * llCos((float)step / steps * TWO_PI);
            rotation rot = llEuler2Rot(<arc.x + offset, arc.y, arc.z>);
            rot.s = -rot.s;
            llSetRot(rot * (startrot * llGetRot()));      
            if ((++step) > steps)
                step = 1;
} else { llSetTimerEvent(0.0); llSetRot(startrot); llSetTouchText("Rock"); swing = FALSE; } }}

 

  • Like 1
Link to comment
Share on other sites

I never liked the approach presented in the OP, it is jerky and costly

A Key Framed Motion is preferable IMO

// simple rcocking script by Dora Gustafson, Studio Dora 2014// rocks around the prim's Y-axis// Low lag Key Framed Motion (the script may be removed and the rocking will continue)// Must be reset after being moved or turned to new location// ref: http://wiki.secondlife.com/wiki/User:Dora_Gustafson/Pendulum_motionfloat angle=0.2; // max swing from resting (radians)float period=2.0; // time in seconds for one full cyclefloat steps=24.0; // number of Key Frameslist KFMlist=[];integer swing=TRUE;rotation baseRot;default{    state_entry()    {        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);        baseRot = llGetRot();        float dT = period/steps;        dT = llRound(45.0*dT)/45.0;        if ( dT < 0.11111111 ) dT = 0.11111111;        float angleU=0.0;        float angleV;        float step=0.0;        while ( step < steps )        {            step += 1.0;            angleV = angle*llCos( TWO_PI*step/steps + PI_BY_TWO);            KFMlist += [llEuler2Rot(< 0.0, angleV-angleU, 0.0>), dT];            angleU = angleV;        }    }    touch_start( integer n)    {        llSetKeyframedMotion( [], []);        llSleep(0.2);        llSetRot( baseRot);        if ( swing ) llSetKeyframedMotion( KFMlist, [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]);        swing = !swing;    }    on_rez( integer n) { llResetScript(); }} 

 

:smileysurprised::):smileyvery-happy:

  • Like 2
Link to comment
Share on other sites

Dora - Many thanks for the keyframed script! It is definitely much smoother than the original script I was using.

At this moment, when I rotate the chair it will stay where I put it and rock in the new direction only if I reset the script. Is this the only way, to reset the script whenever I decide to turn it? It appears I'm still at square one, albeit with a much smoother script. :matte-motes-tongue:

Link to comment
Share on other sites

You can move the motion computation from state_entry() to the touch_start() event
Move all lines except the first one to the touch_start()event
They should be executed only when 'swing' is true and before llSetKeyframedMotion() is called

Now the motion is computed when the chair is at rest just before it starts rocking

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

I hope you will learn some more scripting from this
That would make it legit for me to give scripts away in this forum:)

// simple rocking script by Dora Gustafson, Studio Dora 2014
// rocks around the prim's Y-axis
// Low lag Key Framed Motion (the script may be removed and the rocking will continue)
// Must be reset after being moved or turned to new location
// ref: http://wiki.secondlife.com/wiki/User:Dora_Gustafson/Pendulum_motion
// v1.1 no need for reset after move or turn

float angle=0.2; // max swing from resting (radians)
float period=2.0; // time in seconds for one full cycle
float steps=24.0; // number of Key Frames
list KFMlist=[];
integer swing=TRUE;
rotation baseRot;

default
{
    state_entry()
    {
        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
        float dT = period/steps;
        dT = llRound(45.0*dT)/45.0;
        if ( dT < 0.11111111 ) dT = 0.11111111;
        float angleU=0.0;
        float angleV;
        float step=0.0;
        while ( step < steps )
        {
            step += 1.0;
            angleV = angle*llCos( TWO_PI*step/steps + PI_BY_TWO);
            KFMlist += [llEuler2Rot(< 0.0, angleV-angleU, 0.0>), dT];
            angleU = angleV;
        }
    }
    touch_start( integer n)
    {
        llSetKeyframedMotion( [], []);
        llSleep(0.2);
        if ( swing )
        {
            baseRot = llGetRot();
            llSetKeyframedMotion( KFMlist, [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]);
        }
        else llSetRot( baseRot);
        swing = !swing;
    }
    on_rez( integer n) { llResetScript(); }
}

 

It is not changed exactly the way I described but it works. You could try and figure out why

:smileysurprised::):smileyvery-happy:

Edit: redundant line removed and logic reinforced

  • Like 2
Link to comment
Share on other sites


Dora Gustafson wrote:

I hope you will learn some more scripting from this

That would make it legit for me to give scripts away in this forum:)

:smileysurprised:
:)
:smileyvery-happy:

i very much agree with this sentiment. Is the thought that people shouldnt do other peoples work for them, but is a helpy forum this, and while is experienced scripters come looking for debug help is also new people who just starting out. Also most of the things new people struggle with are the algo fundamentals / basics. So I think is legit to help them learn that, and if that means providing them with a simple script that demo the fundamentals then do it

+

other thing is that for more complex stuff then I personal look to those who do help. Like for example on my previous account I actual bought your sit rotation tool. I could have spent some hours messing about making my own but was a whole lot easier to just buy it off you. Was a pretty worthwhile investment I thought

Link to comment
Share on other sites


Kallie Barrowstone wrote:

I know that there has got to be a simple fix for this (at least I hope!) Below is the script I'm using for my rocking chair. My problem is that when I turn the chair to face another direction it will reset itself to the original position when you click to begin rocking. I would love to be able to turn the chair to face any direction and have it rock as expected when clicked. 

I'm not even partially lsl literate, so any help from those more knowledgable than me is greatly appreciated!

 
... pirated script from http://www.free-lsl-scripts.com/cgi/freescripts.plx?ID=860 snipped ...

 

For future reference- do NOT post scripts you have found elsewhere on the internet into this forum, it violates both copyright laws and the ToS 2.3 (2nd paragraph) which may result in having your account banned.

Link to comment
Share on other sites

LepreKhaun wrote:

... pirated script from http://www.free-lsl-scripts.com/cgi/freescripts.plx?ID=860 snipped ...

For future reference- do NOT post scripts you have found elsewhere on the internet into this forum, it violates both copyright laws and the ToS 2.3 (2nd paragraph) which may result in having your account banned.


 all the scripts contributed to the Free LSL Script Library are either Creative Commons licensed or Public Domain. All given freely to the community by the contributors. Is nothing pirated about the OP posting or in using the script

note also the use of SetLocalRot(rotation x) in the Library version and the OP posted script SetLocalRot(rotation z). This last (rotation z) is in a script in just about every freebie script box in SL. Is every indication from (rotation z) that OP got it inworld and has no idea who wrote the original (rotation x) script

+

talking about no idea. These functions in the scripts

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()));}

 

they were put in the wiki on 29 Aug 2004. Editor Ezhar Fairlight

they were written by Aaron Perkins who contributed them to the community 17 Mar 2004. http://forums-archive.secondlife.com/15/d0/11048/1.html

without which the swing script would not work at all. And probably every LSL script written ever since with rotating wheels and swingy spinny things. Are all those zillions of other scripters even aware of this? No. Even tho is publicly available to search for and know. And the original script has his name in it at the top even

was the author of the LSL Script Library swing script aware of this. No. Was made available by Aaron before they even started in SL

also the swing script was posted at least as far back as 2009 : https://www.xstreetsl.com/forum_archive/modules.php?name=Forums&file=viewtopic&p=639053

and here and here and here:

http://community.secondlife.com/t5/LSL-Scripting/Swing-Script/m-p/2011235/highlight/true#M17362

http://community.secondlife.com/t5/LSL-Scripting/How-do-I-change-the-rotation-on-a-simple-swing-script-to-make-it/m-p/1555321/highlight/true#M11215

http://community.secondlife.com/t5/LSL-Scripting/Need-help-with-a-Rocking-Pivot/m-p/878875/highlight/true#M2316

The original author of the swing is still very much active in SL. Have they come on the forums and go hey !!! watcha doing with my script ??? No

did you go on those posts and start with the heavies? No. So is this just a recent development in your life?

i think that before you start with the !!! O.M.G !!! PIRATES !!! then maybe best chill out a bit. And also I hope that in your own scripts that you gave Aaron a credit and everyone else you borrowed from. or O.M.G !!! PIRATE !!! or maybe you just didnt know. And maybe your googlefu only works when is people new to LSL scripting

+

is ways to help learn new people about crediting. Can just say to them is best to give a credit if they do know who is the original contributor. Is no need to heavy them over scripts freely given to the community by the contributors

Link to comment
Share on other sites


irihapeti wrote:

LepreKhaun wrote:

... pirated script from
snipped ...

For future reference- do
NOT
 post scripts you have found elsewhere on the internet into this forum, it violates both copyright laws and the
 which may result in having your account banned.

 all the scripts contributed to the Free LSL Script Library are either Creative Commons licensed or Public Domain. All given freely to the community by the contributors. Is nothing pirated about the OP posting or in using the script

note also the use of SetLocalRot(rotation x) in the Library version and the OP posted script SetLocalRot(rotation z). This last (rotation z) is in a script in just about every freebie script box in SL. Is every indication from (rotation z) that OP got it inworld and has no idea who wrote the original (rotation x) script

+

talking about no idea. These functions in the scripts
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()));}

 

they were put in the wiki on 29 Aug 2004. Editor Ezhar Fairlight

they were written by Aaron Perkins who contributed them to the community 17 Mar 2004.

without which the swing script would not work at all. And probably every LSL script written ever since with rotating wheels and swingy spinny things. Are all those zillions of other scripters even aware of this? No. Even tho is publicly available to search for and know. And the original script has his name in it at the top even

was the author of the LSL Script Library swing script aware of this. No. Was made available by Aaron before they even started in SL

also the swing script was posted at least as far back as 2009 :

and here and here and here:

The original author of the swing is still very much active in SL. Have they come on the forums and go hey !!! watcha doing with my script ??? No

did you go on those posts and start with the heavies? No. So is this just a recent development in your life?

i think that before you start with the !!! O.M.G !!! PIRATES !!! then maybe best chill out a bit. And also I hope that in your own scripts that you gave Aaron a credit and everyone else you borrowed from. or O.M.G !!! PIRATE !!! or maybe you just didnt know. And maybe your googlefu only works when is people new to LSL scripting

+

is ways to help learn new people about crediting. Can just say to them is best to give a credit if they do know who is the original contributor. Is no need to heavy them over scripts freely given to the community by the contributors

Software piracy is defined in the industry as "the unauthorized copying, reproduction, use, or manufacture of software products." If you have an issue with that definition, good luck in getting it changed.

 

Any issue with Linden Labs Terms of Service can only be answered by not using the service in question. Or I suppose you could go argue with them about it. Good luck with that as well.

 

Warning that a stove is hot and they may get burned if they continue playing irresponsibly around it may not be what children at play want to hear. However, that does not make the stove any cooler nor the danger less acute.

 

My advice to you is, if you don't believe in the possibilty of getting scalded, is to carefully read http://community.secondlife.com/t5/LSL-Scripting/llSetTimerEvent/td-p/2482379 before testing it out yourself.

 

Link to comment
Share on other sites

hope you as a wiki editor are going to go thru the wiki and credit all the authors of the codes on there. You wouldnt want to be associated with non-crediting would you??

maybe you can use your googlefu to track down all the original authors and ask them: What license did you release your stuff under? bc some of our editors unfortunately just copypasta your codes and so we dont know anymore? In the meantime to maintain my righteousness, and is gunna break my heart to do this but yanno, I am delete all non-credited codes off the wiki until i know for a absolute fact what was the license. Be a shame tho if the wiki got pretty much rendered useless bc: if (nocredit == piracy) delete;

as you say: good luck with that

or maybe we just use some commonsense bc wiki

and maybe we extend same commonsense to new people bc they found a non-credited script in a SL freebie dumpster and post it on here. Which is what actually happened here with OP

if OP is a pirate according to you then so is every wiki editor who ever copypasta codes on the wiki without crediting them. So you need get busy if you want to maintain your righteousness. Or maybe thats different somehow

Link to comment
Share on other sites

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