Randomize and actions

Posted By: CBSection31

Randomize and actions - 06/06/07 02:21

Hey everyone,

I have several models next to each other in a level that all have the same action assigned to them. The action has a loop that calls for the model to move via c_move after a random period of time. I have set this up using the random command. I have randomize() set up properly (I think), so that the time before they move varies every loop.

So basically, it works something like this:

Code:

action lalala
{
var looptime;
while (1)
{
randomize();
looptime=int(random(100))+20;
wait(looptime); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}



The problem is, each model that has the action moves at the same time. So, each loop the value of looptime changes successfully. BUT, the value of looptime is the same for EVERY model assigned the action.

Is there a way for the value to be random for each model, even if they share the same action?

Thanks!
Posted By: xXxGuitar511

Re: Randomize and actions - 06/06/07 03:41

...move it after the {. And also, wait(x); waits by frames, not ticks. use wait(-x); to wait seconds. ex: wait(-0.5); = wait half a second...

Code:

action lalala
{
var looptime;
while (1)
{
randomize();
looptime=int(random(100))+20;
wait(looptime); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}



Even better, use entity skills instead!

Code:

action lalala
{
while (1)
{
randomize();
my.skill1 = int(random(100))+20;
wait(-my.skill1); // wait between 20 and 120 ticks
c_move (blahblahblah);
}
}


Posted By: CBSection31

Re: Randomize and actions - 06/06/07 07:24

Thanks for your fast reply!

I switched the variables over to entity skills. The other mistake was just a typo of mine in making this post. Unfortunately, all the entities still move at the same time.

It's like the same random number is used for EVERY model that has the action attached, instead of coming up with a random number for each individual model.

I'll go ahead and post the exact code I'm using, so that someone can give me an idea of how I'm screwing this up haha. The action is for small bugs that crawl around the level randomly.

Code:

action bugs
{
while (1)
{
randomize();
my.skill21=int(random(300))+200; // Random number of frames to wait before moving
my.skill20=0; // Counter for current frame of sanding
ent_animate(me,NULL,0,0);
while (my.skill20<my.skill21) // Is current frame less than total number of standing still frames?
{
ent_animate(my,"stand", my.skill48,anm_cycle); // play the "stand" frames animation
my.skill48 += 1 * time; // "stand" animation speed
my.skill48 %= 100; // loop animation
my.skill20+=1; // increase counter by one
wait (1);
}
my.skill22=0; //Counter for current frame of walking
ent_animate(me,NULL,0,0); // reset animation
while (my.skill22<20) // Is current frame less than total number of movement frames?
{
ent_animate(my, "walk",my.skill46,anm_cycle); // play the "walk" frames animation
my.skill46 += 12 * time; // "walk" animation speed
my.skill46 %= 100; // loop the animation
randomize();
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, ignore_me | ignore_passable);
temp.x = int(-(random(4)));
temp.y = 0;
c_move (my, temp.x, nullvector, ignore_passable | glide); // move bug randomly along floor
randomize();
my.skill24=int(random(5))+1; // set random value to my.skill24 to determine if the bug should rotate
randomize();
my.skill23=int(random(179))+1; // set random value to my.skill25 to determine degree of bug rotation
if (my.skill24==1) // if my.skill24 is 1, then the bug will rotate clockwise
{
randomize();
c_rotate (my, vector((int(random(50))+1),0,0),ignore_passable); // rotate
}
if (my.skill24==2) // if my.skill24 is 2, then the bug will rotate counter-clockwise
{
randomize();
c_rotate (my, vector((-int(random(50))+1),0,0),ignore_passable); // rotate
}
my.skill22+=1; // increase counter by one
wait (10*time);
}
}

}


Posted By: nipx

Re: Randomize and actions - 06/06/07 14:30

I dont know about your problem but you only have to call randomize() _once_.
Best would be at the startup.


nipx
Posted By: CBSection31

Re: Randomize and actions - 06/06/07 17:33

^
Interestingly, that fixed the problem. Thank you very much!
Posted By: nipx

Re: Randomize and actions - 06/06/07 18:23

No problem.


I guess its because randomize() uses the GetTime (returns the time from booting till now in milliseconds) as you do in c. And all this actions start simultaneously, so they get the absolutely same time -> they are initalized with the same number -> return the same random number.

Just a little supposition, correct me if Im wrong


nipx
© 2024 lite-C Forums