Limit walking speed to min and max values

ABK

Well-known member
hey, i want the walking speed go higher when i press down, and lower when i press up, but i cant figure it out, it works nicely with z values but with speed it doesnt work, maybe im doing it wrong, heres what i have using z , when i change it to speed and give min 22 and max 55 then it just doesnt work :
How do you guys limit the speed and put a clamp on it ?

In this script when character is at Z 800 then his speed is not accelerating anymore, when hes at z 600 then speed is not decelerating , now i just want to make it work by using walking speed values so its consistent.

Code:
            @script
         void self = getlocalvar("self");
        int pindex     = getentityproperty(self,"playerindex");
         float sp = getentityproperty(self,"speed");
         float z = getentityproperty(self,"z");
         void yVel = getlocalvar("yVel"+self);
         int minspeed = 22;
         int maxspeed = 55;
    void moveup     =  playerkeys(pindex, 0, "moveup");
    void movedown     =  playerkeys(pindex, 0, "movedown");
    void vspeed ;
     settextobj(1, 250 , 280 , 1, 1,getentityproperty(self,"speed")/100+"speed", openborvariant("elapsed_time")+2000);
     settextobj(2, 250 , 180 , 2, 2, z , openborvariant("elapsed_time")+2000);
           if ( !vspeed ){
         setlocalvar("vspeed",22*1000);
        }
      if   (getentityproperty(self,"speed") && z >= 600 && moveup ) {
        changeentityproperty(self, "speed", (getentityproperty(self,"speed"))- 0.05);
        }
         if   (getentityproperty(self,"speed")&& z <= 800 && movedown ) {
        changeentityproperty(self, "speed", (getentityproperty(self,"speed"))+ 0.05);
        }
    @end_script
 
when i change it to speed and give min 22 and max 55 then it just doesnt work :

Well, I can see defined speed limits but I don't see any script applying those limits :rolleyes:.

Let's clear up confusion here: do you want to modify existing script to apply those limits ? OR do you want to copy that script to create new one which apply those limits?
 
yes, i had :
int minspeed = 22
int maxspeed = 55

and i had :
if (getentityproperty(self,"speed") && z >= minspeed && moveup ) {
changeentityproperty(self, "speed", (getentityproperty(self,"speed"))- 0.05);

it doesnt work and doesnt limit the walkint speed to 22 , but the same script with Z offset limits works fine, thats strange for me.
 
Last edited:
I'm not sure how this works.... I can only assume for now that your entity is not moving in z axis at all, otherwise it would be odd to see speed increases/decreases when moving up/down.
Let me confirm this: you can adjust this entity's speed by pressing up or down but it's not moving yet until left or right is pressed, right?
 
Ok this is for scaling player , when character is closer to screen he needs to move faster cause hes bigger, when hes far from screen , he needs to walk slower like hes actually farther from camera .
I have separate scaling script, i need another one for "scaling" walking speed but i need limits for it.
 
You know, if you already have sprite scaling script, why not declaring speed scaling script there also?
 
i did and it works but i want that speed limit for others tuff like accelerating with a car or slowly speeding up from walk to run and for this i have to figure out how to put a cap on speed x and z axes.
 
Ah so you have 2 factors which defines speed limit: scale ratio and acceleration.
That means you need to add speed limit in acceleration script + add scale ratio factor there.
 
Back
Top Bottom