Sign in to follow this  
internet_trends

Help with speed to platform distance scaling?

Recommended Posts

I'm in the process of creating an endless runner, and one of the features that I've been trying to implement effectively is a distance between platforms that scales with the speed you're running (-hspeed of the platforms). Essentially, the faster you run, the further you can jump. The problem is that I really don't know how to go about doing it. Here is my code for alarm[0] in the controller object that generates the platforms:

var len =irandom_range(global.playerspeed*10,global.playerspeed*16);
var rany = irandom_range(-20,20);
var floor_number = 0;
xx = 16
repeat (len){    
    new_floor = instance_create(room_width+xx,160+rany,obj_floor)
    var yy2 = 0; 
    repeat(20){
        yy2 += 16
        instance_create(new_floor.x, new_floor.y + yy2, obj_floor);
    }
    floor_number ++
    if (floor_number < len - 4 and floor_number > 4 ){
        //if irandom(100) < 10 instance_create(room_width+xx,new_floor.y - 1, obj_enemy);
    }
    
    xx += 16;
}
alarm[0] = ????

I'm essentially trying to get the alarm to set to a scaling value at the end. Does anyone have any ideas? Am I going about the platform generation the wrong way? Any help or advice would be much appreciated!

 

 

 

 

 

 

 

Oh, and I also found that if the len == 1 global.playerspeed == 3 and alarm[0] == 10, the floors are seemingly spaced apart by their own width like this:

2nq5s2v.png

I've been playing around with those ratios but they don't seem to scale up properly. Maybe I'm missing something, though...

Share this post


Link to post
Share on other sites

In a similar project I used this:

float gap_limit = SLOW_GAP_LIMIT * speedRatio;
std::uniform_real_distribution<float> gapRand(0.0f, gap_limit);

Where speedRatio = speed / startingSpeed and SLOW_GAP_LIMIT was a tuned value.

 

You'll probably have to play with it a bit. That worked for the project it was in because the maximum speed kept it in a sane range. If we had uncapped the speed and somehow a player was able to continue accelerating for long enough it may have stopped working at some point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this