• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

PLEASE HELP Going up slopes platformer

W

Willowwisp001

Guest
how do i go up slopes on platformers?
upload_2016-12-25_2-11-2.png
my code i have atm
Code:
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_enter);
key_jump_held = keyboard_check(vk_enter);
key_down = keyboard_check(vk_down);


//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

//Jumps
if (place_meeting(x,y+1,obj_wall))
{
    jumps = jumpsmax;
}
else
{
    if (jumps == jumpsmax) jumps -=1;
}

if (key_jump) && (jumps > 0)
{
    jumps -= 1;
    vsp = -jumpspeed;
}

if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-jumpspeed/2)


var hsp_final = hsp + hsp_carry;
hsp_carry = 0;

//Horizontal Collision
if (place_meeting(x+hsp_final,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp_final),y,obj_wall))
    {
        x += sign(hsp_final);
    }
    hsp_final = 0;
    hsp = 0;
}
x += hsp_final;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;

//Animate
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wall))
{
    if (move!=0)
    {
        sprite_index = spr_player_run;
        image_speed = 1;
    }
    else sprite_index = spr_player_idle; image_speed = 0.5;
}
else
{
    if (vsp < 0) sprite_index = spr_player_jump; else sprite_index = spr_player_fall;
}
 

Attachments

TrunX

Member
Check if x+hsp && y-abs(hsp) is collision free, move it that way and move it down to the obj_wall again in case the angle is lower than 45°.
 
W

Willowwisp001

Guest
Check if x+hsp && y-abs(hsp) is collision free, move it that way and move it down to the obj_wall again in case the angle is lower than 45°.
Can you put this into code pls? heh -u-U
 

TrunX

Member
Thats the code I use for horizontal movement in my current project:

Code:
//horizontal movement

if !place_free_rounded(x,y+1) && place_free_rounded(x+xspeed_delta,y+1) //slopes down
{
    x+=xspeed_delta;
    move_contact_solid_ver(270);
}
else if place_free_rounded(x+xspeed_delta,y) //plane
{
    x+=xspeed_delta;
}
else if place_free_rounded(x+xspeed_delta,y-abs(xspeed_delta)-1) //slopes up
{
    y-=abs(xspeed_delta)+1;
    x+=xspeed_delta;
    move_contact_solid_ver(270);
}
else
{
    move_contact_solid_hor(dir);
    xspeed=0;
}
place_free_rounded() is a custom script that can be replaced with "!place_meeting(x,y,obj_wall)"
xspeed_delta can be replaced with hsp
move_contat_solid_ver (&_hor) can be replaced with the build in move_contact functions or the while()-alternative you are already using.
 
W

Willowwisp001

Guest
like this?

//horizontal movement

if !!place_meeting(x,y,obj_wall)x,y+1) && !place_meeting(x,y,obj_wall)x+hsp,y+1) //slopes down
{
x+=hsp;
while(270);
}
else if !place_meeting(x,y,obj_wall)x+hsp,y) //plane
{
x+=hsp;
}
else if !place_meeting(x,y,obj_wall)x+hsp,y-abs(hsp)-1) //slopes up
{
y-=abs(hsp)+1;
x+=hsp;
while(270);
}
else
{
while(dir);
xspeed=0;
}
 
Top