Slope travel distance - move speed

N

NoFontNL

Guest
I'm creating a platformer and added slopes using Shaun Spalding's slope code.

The problem here is, it automatically moves you up when you are going to collide with a slope, and you will move diagonally with the same speed as if you were on the ground and only moving horizontally. This means you will travel more distance when going up / down a slope than when you only move horizontally, but it should be less.

Is there a way, to detect when you go up a slope (not just standing on a object called slope, but litterally going up and down) and then setting the movespeed accordingly?
 

Kyrieru

Member
I'm creating a platformer and added slopes using Shaun Spalding's slope code.

The problem here is, it automatically moves you up when you are going to collide with a slope, and you will move diagonally with the same speed as if you were on the ground and only moving horizontally. This means you will travel more distance when going up / down a slope than when you only move horizontally, but it should be less.

Is there a way, to detect when you go up a slope (not just standing on a object called slope, but litterally going up and down) and then setting the movespeed accordingly?
Well, if you set a previous_y variable before the collision code, you can compare it to Y after the collision code ends.
Using this you can get the angle of the slope and use it to change the movement speed.

This would only take effect after the first frame of being on the slope, though, so it depends if that's enough for you.
Otherwise, you need to look into the slope code and make the speed change happen as it encounters a slope and before it adjusts the Y value.
 

Gzebra

Member
Try and fiddle around with this code, maybe you can come up with a solution.

Create event:
Code:
vMove=0
hMove=0
dMove=0
BeginStep event:
Code:
if(keyboard_check(vk_up)) 
{ y-=1 }
if(keyboard_check(vk_down))
{ y+=1 }
if(keyboard_check(vk_left))
{ x-=1 }
if(keyboard_check(vk_right))
{ x+=1 }

if(yprevious-y || y-yprevious)
{vMove=1}
else
{vMove=0}

if(xprevious-x || x-xprevious)
{hMove=1}
else
{hMove=0}

if(hMove && vMove )
{dMove=1}
else
{dMove=0}
Draw event:
Code:
draw_text(0,0,vMove)
draw_text(0,16,y)
draw_text(0,32,yprevious)
draw_text(0,48,hMove)
draw_text(0,64,x)
draw_text(0,80,xprevious)
draw_text(0,96,dMove)
 
Top