GMS 2 8 directional movement and collisions?

lamatoast

Member
Hi everyone, i have made a top down control system that uses lengthdir_x and lengthdir_y to move. The system is good because you move the same speed in every direction but i am not sure how to handle collisions, please help?.
 

Bentley

Member
This might work:
Code:
var hspd = (keyboard_check(vk_right) - keyboard_check(vk_left)) * move_speed;

if (!place_meeting(x + hspd, y, o_solid))
{
    x += hspd;    
}
else
{
    while (!place_meeting(x + sign(hspd), y, o_solid))
    {
        x += sign(hspd);    
    }
    hspd = 0; // Set to 0 in case code below is based on what "hspd" is
}
You'd do the same for vertical movement.
 
Last edited:
Top