0
\$\begingroup\$

I am making a basic point and click adventure game. I can make the player object move towards the location of a mouse click and collide with walls, but movement stops the instant a collision occurs. I would like the player object to keep moving (slide along the wall) and get as close as it can to the mouse click location, without passing through a wall of course. I have Create, Step, Collision & Global Mouse click events. Please see below for code and diagrams.

Any help will be much appreciated.

The player object (green square) should move towards the mouse click location, collide on the X axis, then slide down the Y axis before stopping in the corner of the walls

This is my player object. It is set to solid and uses a collide event to collide with the walls

Create Event code:

//stop player moving on create
enum mouse {
    none    
}
xx = mouse.none;
yy = mouse.none;
player_move_speed = 2;

//init
collision_speed = player_move_speed + 1;

Step Event code:

//general keys
if keyboard_check_pressed(vk_escape) {game_end()}


//point and click movement
if (xx != mouse.none and yy != mouse.none) {
    move_towards_point(xx,yy,player_move_speed);
} else {
    speed = 0;  
}

if (distance_to_point(xx,yy) < collision_speed) {
    xx = mouse.none;
    yy = mouse.none;
}

Global Left Pressed code:

xx = mouse_x;
yy = mouse_y;
\$\endgroup\$

This site is temporarily in read only mode and not accepting new answers.

Browse other questions tagged .