• 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!

SOLVED How can I make "ramps" with solid squares

Alemar5

Member
Hi everyone!
Some time ago I found a code that made more precise collisions and it still works, however I wanted to make some kind of ramp by changing the angle of the square, I have looked for several tutorials on the internet but I have only seen it in platform games, my game is an rpg So could someone help me to know how to do this? If someone could help me with this I would really appreciate it :,3
Then I leave you the code of the collisions and movement, I will also leave an image that better explains what I mean.

GML:
///Create

vel = 3;  //speed
is = 0.4; //Animation speed
GML:
if keyboard_check(global.left)
{
    repeat(vel)
    {
        
        if place_free(x-5,y)
        {
            x--;
            is = 0.4
        }
        else
        {
            is = 0
            image_index = 0
        }
    }
    sprite_index = spr_prota_izquierda
    image_speed = is
}

if keyboard_check(global.right)
{
    repeat(vel)
    {
        if place_free(x+5,y)
        {
            x++;
        }
    }
    sprite_index = spr_prota_derecha
    image_speed = is
}

if keyboard_check(global.up)
{
    repeat(vel)
    {
        if place_free(x,y-4)
        {
            y--;
        }
    }
    sprite_index = spr_prota_arriba
    image_speed = is
}

if keyboard_check(global.down)
{
    repeat(vel)
    {
        if place_free(x,y+2)
        {
            y++;
        }
    }
    sprite_index = spr_prota_abajo
    image_speed = is
}
(the collision object only has the "solid" box checked and the collision mask is in "precise")

Captura de pantalla 2021-10-17 105216.pngCaptura de pantalla 2021-10-17 105455.png
I thank you all in advance for your help :,3
 

Jakylgamer

Member
well you can give this a go its not perfect but it does "slide" along the walls
players end step event
GML:
var xmot, ymot ,xaxis,yaxis,move,dir,spd = 3

xaxis = keyboard_check(ord("D")) - keyboard_check(ord("A"))
yaxis = keyboard_check(ord("S")) - keyboard_check(ord("W"))
move  = (xaxis != 0 || yaxis != 0) * spd
dir   =  point_direction(0,0,xaxis,yaxis)

x     = xprevious;
y     = yprevious;

for(var i=0; i<90; i+=5) {

    xmot=x+lengthdir_x(move,dir+i);
    ymot=y+lengthdir_y(move,dir+i);
    if !place_meeting(xmot,ymot,obj_solid){
        x=xmot;
        y=ymot;
        exit;
    }
    xmot=x+lengthdir_x(move,dir-i);
    ymot=y+lengthdir_y(move,dir-i);
    if !place_meeting(xmot,ymot,obj_solid){
        x=xmot;
        y=ymot;
        exit;
    }

}
 

Alemar5

Member
well you can give this a go its not perfect but it does "slide" along the walls
players end step event
GML:
var xmot, ymot ,xaxis,yaxis,move,dir,spd = 3

xaxis = keyboard_check(ord("D")) - keyboard_check(ord("A"))
yaxis = keyboard_check(ord("S")) - keyboard_check(ord("W"))
move  = (xaxis != 0 || yaxis != 0) * spd
dir   =  point_direction(0,0,xaxis,yaxis)

x     = xprevious;
y     = yprevious;

for(var i=0; i<90; i+=5) {

    xmot=x+lengthdir_x(move,dir+i);
    ymot=y+lengthdir_y(move,dir+i);
    if !place_meeting(xmot,ymot,obj_solid){
        x=xmot;
        y=ymot;
        exit;
    }
    xmot=x+lengthdir_x(move,dir-i);
    ymot=y+lengthdir_y(move,dir-i);
    if !place_meeting(xmot,ymot,obj_solid){
        x=xmot;
        y=ymot;
        exit;
    }

}
Really thank you very much, I already implemented it in my game and with a couple of adjustments it was perfect, Thanks! :3
 
Top