Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Variable Rotation (startup and Slowdown)

Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
05-10-2006 05:46
Anyone know how somebody would make variable rotation (such as a engine starting p then slowing down)

I wanna make an Engine that spins to full power when I start it up then slows down when turned off.

I am kinda stumped on this one.

Thank guys!
Aislin Wallaby
Registered User
Join date: 4 Mar 2005
Posts: 27
05-10-2006 09:05
Are you talking about spinning one prim, a linked set, or a texture? If you're spinning a singular prim or a linked set, I would suggest stepping through llTargetOmega() with variable speed, so it would look something like this: I recommend llTargetOmega since it's all client-side rendering, now if you want to make things actually rotate, you'll need to do something similar but use an ongoing llSetRot() to make the rotation happen. If you're using physics to rotate the whole thing and it isn't attached to anything, then you can just replace llTargetOmega with llSetTorque (and a few additional modifications) and the thing will spin.

CODE


integer maxspin = 5; //top spin rate
integer spindifference = 1; //rate to reduce each step
integer timing = 3; //timing in seconds between steps
integer started = FALSE;
integer currentspin;

default
{
state_entry()
{
@resting; //setting a point for the script to bail out of the timer loop from
}
touch_start(integer touched)
{
llSetTimerEvent(timing); //setting the timer interval
}
timer()
{
if (started && currentspin=0) //checks to see if we've gotten to zero when throttling down
{
started = FALSE;
llSetTimerEvent(0); //telling the timer to not run anymore after this
jump resting; //making sure we get out of this timer execution
}
if (started == FALSE && currentspin=5) //checks to see if we've already gotten to the max when throttling up
{
started = TRUE;
llSetTimerEvent(0);
jump resting;
}

else if (started && currentspin !=0) // if we aren't already down we drop one level
{
currentspin-=spindifference;
llTargetOmega(<0,0,1>,currentspin, 1);
}
else if (started=FALSE && currentspin!=maxspin) //if we aren't already up we go up one level
{
currentspin+=spindifference;
llTargetOmega(<0,0,1>,currentspin,1);
}
}
}
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
05-10-2006 16:34
Nice ok cool.

Yeah imagine a jet turbine

I wanted a startup/ slowdown

Its says the variable resting isn't named within scope.

Shall I just make a Integer at the top with that name?

Thanks a bunch for your help
Aislin Wallaby
Registered User
Join date: 4 Mar 2005
Posts: 27
05-10-2006 17:49
fixed the problem with the jump, it has to be placed after it's called so it'll compile correctly, and fixed a logic error as well, here's the revised code:

CODE

integer maxspin = 10; //top spin rate
integer spindifference = 1; //rate to reduce each step
integer timing = 3; //timing in seconds between steps
integer started = FALSE;
integer currentspin = 0;

default
{
state_entry()
{

}
touch_start(integer touched)
{
llSetTimerEvent(timing); //setting the timer interval
}
timer()
{
if (started == TRUE && currentspin==0) //checks to see if we've gotten to zero when throttling down
{
started = FALSE;
llTargetOmega(<0,0,1>,currentspin, 1);
llSetTimerEvent(0); //telling the timer to not run anymore after this
jump resting; //making sure we get out of this timer execution
}
if (started == FALSE && currentspin==maxspin) //checks to see if we've already gotten to the max when throttling up
{
started = TRUE;
llTargetOmega(<0,0,1>,currentspin, 1);
llSetTimerEvent(0);
jump resting;
}

if (started == TRUE & currentspin > 0) // if we aren't already down we drop one level
{
currentspin-=spindifference;
llTargetOmega(<0,0,1>,currentspin, 1);
}
if (started == FALSE & currentspin<maxspin) //if we aren't already up we go up one level
{
currentspin+=spindifference;
llTargetOmega(<0,0,1>,currentspin,1);
}
@resting;
}

}