Random Speed

  • Thread starter Thread starter Goliath
  • Start date Start date
G

Goliath

Guest
After searching through the forum i found nothing about random speed, so i came with something similar, is not 100% random but does the job.

Code:
void randspeed()
{ // Set random speed betwen 3 speed values
	void self = getlocalvar("self");
	int r = rand()%60; // Get Random value
	
	if(r < 30)
	{changeentityproperty(self, "velocity", -1, 0, 0.5);}
	else if(r < 0)
	{changeentityproperty(self, "velocity", -0.5, 0, 1.5);}
	else
	{changeentityproperty(self, "velocity", -1, 0, 2);}
}

declare

@cmd randspeed

on frames to call it, you can change the speed values in the script.
 
in fact, there is a script for that by Mtrain

Code:
/// by Mtrain
void rspeed()
// gives a random walk speed
{
   void spd = getentityproperty(getlocalvar("self"),"speed");
   void ri = rand()%1000+1000;
   void ra = rand()%1000+1000;
   float sp = spd + ( ri*0.001 + ra*0.001 )/10.0;
   changeentityproperty(getlocalvar("self"), "speed", sp);
}
 
place it in walk animation
Code:
@script
    void self = getlocalvar("self");
    if( frame == 1){
      int r = rand()%30;
      if( r > 11){
        changeentityproperty(getlocalvar("self"), "speed", 2.7);
      } else if( r < -10){
  changeentityproperty(getlocalvar("self"), "speed", 3.1);
      } else if( r < 0){
      changeentityproperty(getlocalvar("self"), "speed", 2.4);
      } else if( r > 0){
        changeentityproperty(getlocalvar("self"), "speed", 3.4);
      }
    }
	@end_script
 
Back
Top Bottom