Jump to content

I need assistance in making a script to put random force on a flexi prim every second or so


Dracgon Zuhrah
 Share

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

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

Recommended Posts

Start here >>> http://wiki.secondlife.com/wiki/Getting_Ready_to_Learn_LSL .  Then work through a few of the basic tutorials at http://wiki.secondlife.com/wiki/LSL_Tutorial .  It can also help to take a course in LSL scripting at someplace like Builders Brewery or Caledon University.  For many people -- fast learners -- it is also smart to get hold of full perm scripts and try modifying them a little bit at a time until you get a feel for how they work.  When you finally have written a script of your own and have questions about how to improve it, post it here and we'll be glad to help.

ETA:  You can't apply a random force to the wiggly end of a flexi prim.  It wiggles only in your viewer, so we have no scripted control over it.  You can move the other end randomly, however, and the wiggly end will respond. One way is to put llSetPos with a random increment into a timer.  That's a typical way for making tails twitch, for example.

  • Like 1
Link to comment
Share on other sites

For flexibles you can apply a force like this:

llSetPrimitiveParams([PRIM_FLEXIBLE, integer boolean, integer softness, float gravity, float friction, float wind, float tension, vector force]);

The last parameter: force, will be applied to the flexi prim.
If it is randomly changed in size and direction and the times when applied is randomly chosen, then you have what you ask for.

Changes in the other parameters are also visible
You may experiment to see what you like best:)

  • Like 1
Link to comment
Share on other sites

While taking Rolig's advice, I found the llsetPrimitiveParams, but now, would i use a command like

interger random = (integer) llFrand (5.0)  

(or whatever range I choose to use) to generate the integers that would go into the <0, 0, 0> area of the set params command? And if so, how would I go about sending the integers to the <0, 0, 0>?

Link to comment
Share on other sites

llFrand() and the vector elements are all float variables so you can skip the integer stage.
Do something like this:

float r = 10.0; // any suitable rangevector force = < llFrand®, llFrand®, llFrand®>;

 If you want numbers symmetrical around zero:

float r = 10.0; // any suitable rangevector force = < 0.5*r-llFrand®, 0.5*r-llFrand®, 0.5*r-llFrand®>;

 

  • Like 1
Link to comment
Share on other sites

Having a bit of trouble getting your suggestion to work, Dora. To be sure, am I still going to need a timer event?

 

Also, this is the script as I have it so far. (I have very little idea what i'm doing still)

default
{
state_entry()
{
llSetTimerEvent(2);
}
timer()
{
float r = 10.0; // any suitable range
vector force = <llFrand®, llFrand®, llFrand®>;
}
}

Link to comment
Share on other sites

You are close, you just miss the llSetPrimitiveParams() call:

float r = 10.0; // any suitable rangedefault{    state_entry()    {        llSetTimerEvent(2);    }    timer()    {        vector force = <llFrand®, llFrand®, llFrand®>;        llSetPrimitiveParams( [PRIM_FLEXIBLE, TRUE, 3, 0.0, 6.0, 0.0, 6.0, force]);    }}

llSetPrimitiveParams() is not the easiest function in LSL so it is a tough one to start with.
Note that it needs all the parameters, not more and not less.
In this example I used some default values.
Read all about it here: llSetPrimitiveParams()

 

  • Like 1
Link to comment
Share on other sites

Thank you very much, Dora. after fiddling with the parameters a little bit, i've gotten it close to just how I had hoped it would be. Is there any way to make the movement more smooth? At the current it's movements are very quick. Oh, also, how would I go about setting the range to say, -10 - 10?

I tried using 

float min= -10.0; 
float max= 10.0;

(and then setting the llFrand to (min + max) I failed, of course)

But to no avail.

Link to comment
Share on other sites

Maybe I'm putting it in the wrong spot, as I said earlier, I have little to no clue what I'm doing. 

default
{
state_entry()
{
integer num = (integer)11.0 -llFrand(22.0));
llSetTimerEvent(0.2);
}
timer()
{
vector force = <llFrand®, llFrand®, llFrand®>;
llSetPrimitiveParams( [PRIM_FLEXIBLE, TRUE, 10, 0.0, 10.0, 10.0, 10.0, force]);
}
}

Is how I have it set up now, and it's not compiling.

Link to comment
Share on other sites


Dracgon Zuhrah wrote:

Thank you very much, Dora. after fiddling with the parameters a little bit, i've gotten it close to just how I had hoped it would be.
Is there any way to make the movement more smooth? At the current it's movements are very quick.

float r = 10.0; // any suitable range

Maybe 10.0 is not a suitable range for you, try another value

I guess a smaller force range would look better.


Dracgon Zuhrah wrote:

Oh, also, how would I go about setting the range to say, -10 - 10?


In an earlier post in this thread the code for this was given to you:

If you want numbers symmetrical around zero:

float r = 10.0; // any suitable rangevector force = < 0.5*r-llFrand®, 0.5*r-llFrand®, 0.5*r-llFrand®>;

 

Link to comment
Share on other sites

You are presented all the ingredients you need, but somehow you can not get it together:(
There can be hundreds of good reasons for that and I don't hold it against you;)

float r = 1.0; // any suitable range
vector force;
default
{
    state_entry()
    {
        llSetTimerEvent(2);
    }
    timer()
    {
        force = < 0.5*r-llFrand®, 0.5*r-llFrand®, 0.5*r-llFrand®>;
        llSetPrimitiveParams( [PRIM_FLEXIBLE, TRUE, 3, 0.0, 0.5, 0.0, 6.0, force]);
    }
}

Copy and paste this script and do not touch anything
It works and looks pretty cool to me when I test it

Link to comment
Share on other sites

Thank you all for the assistance, I haven't had time to try and work out what I was doing wrong today, as I've been busy. But I am certainly reading and studying everything you all have provided. I appreciate it and hope I can work on the script more tonight.

Link to comment
Share on other sites

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