Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

random rotation script

CarloDM Demme
Registered User
Join date: 15 Jun 2007
Posts: 44
06-28-2008 03:43
is it possible to random the speed of rotation.
i'd like that the prim change speed continuously

this is the classic script:

default
{
state_entry()
{
llTargetOmega(<0,0,1>,0.3,PI);
}

}

can someone help me?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-28-2008 06:45
From: CarloDM Demme
is it possible to random the speed of rotation.
i'd like that the prim change speed continuously

llTargetOmega put all the work on the client and free the server from doing anything. That way you can have a nice smooth rotation with constant speed. Each time you want to change speed you have to call the server which must inform all clients over the internet about the change! I don't believe that will ever result in something looking like a continuously speed change. So the answer to your question must be no.
If you can do it with a physical object? It raises so many new questions to be answered... I will leave that for those who know
_____________________
From Studio Dora
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
06-28-2008 07:04
I have one that I made, which I use a lot. The way I do it is to just have the script constantly flipping between two states. Each time it enters a state it randomly generates a new rotation vector. The script is written differently, depending on whether you just want to randomly vary the rotation rate, or whether you want the object to actually change its rotation direction, too. Also you could vary timing by putting in a random llSleep command in each state, to avoid using timers.


Here's an example:

<CODE>
//------ Change the MaxSpeed variable to whatever you want the maximum possible rotation speed to be

float MaxSpeed = 3.0;


default
{
state_entry()
{
float randx_pos = llFrand(MaxSpeed);
float randx_neg = -llFrand(MaxSpeed);

float randy_pos = llFrand(MaxSpeed);
float randy_neg = -llFrand(MaxSpeed);

float randz_pos = llFrand(MaxSpeed);
float randz_neg = -llFrand(MaxSpeed);

float randx = (randx_pos + randx_neg);
float randx = (randy_pos + randy_neg);
float randx = (randz_pos + randz_neg);

llTargetOmega(<randx,randy,randz>,0.3,PI);

// You could also throw in a randomizing value for where you now have 0.3 in the llTargetOmega function....

llSleep(llFrand(3.0)); // ... which causes the rotation to stay the same for up to 3.0 seconds, randomly each time

state Second;
}
}

state Second
{
state_entry()
{
float randx_pos = llFrand(MaxSpeed);
float randx_neg = -llFrand(MaxSpeed);

float randy_pos = llFrand(MaxSpeed);
float randy_neg = -llFrand(MaxSpeed);

float randz_pos = llFrand(MaxSpeed);
float randz_neg = -llFrand(MaxSpeed);

float randx = (randx_pos + randx_neg);
float randx = (randy_pos + randy_neg);
float randx = (randz_pos + randz_neg);

llTargetOmega(<randx,randy,randz>,0.3,PI);

// You could also throw in a randomizing value for where you now have 0.3 in the llTargetOmega function....

llSleep(llFrand(3.0)); // ... which causes the rotation to stay the same for up to 3.0 seconds, randomly each time

state default;
}
}

</CODE>



This script results in your object randomly whizzing around, then suddenly shifting gears and going slow, or suddenly rotating back in the opposite direction, and all the while not doing it in predictable intervals. If you want it more predictable just take out the random factors in the llSleep lines, and if you want it to just rotate in one direction just remove all the calculations of positive and negative xyz values. Then it becomes very simple:


<CODE>

default
{
state_entry()
{

llTargetOmega(<llFrand(3.0),llFrand(3.0),llFrand(3.0)>,0.3,PI);
llSleep(3.0); // Or whatever delay you want...

state Second;
}
}

state Second
{
state_entry()
{

llTargetOmega(<llFrand(3.0),llFrand(3.0),llFrand(3.0)>,0.3,PI);
llSleep(3.0);

state default;
}
}
</CODE>



Of course there are probably more pretty ways to do it, but this is from someone who taught themselves scripting with lots of hair being pulled out in the process... :D
Robin Sprocket
Registered User
Join date: 5 Mar 2006
Posts: 11
Thinning Hair....
06-30-2008 11:59
Of course there are probably more pretty ways to do it, but this is from someone who taught themselves scripting with lots of hair being pulled out in the process...



You mean there's ANOTHER way to learn scripting??!!!
(Rubbing little bald spot...)

Robin