• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2 collision with player controlled by mouse

inarsy

Member
im making a game where the player moves towards the mouse when you hold the left mouse button and i dont know how i would go about doing the collisions with the code that i have.
How would i do the collisions with a wall?

player movement code:

create event:

friction = 1.5;
spd = 0;
max_spd = 24;
acceleration = 3;
angle = 0;

step event:

if (mouse_check_button(mb_left)) {
spd += acceleration;
move_towards_point(mouse_x,mouse_y,spd);
if (spd > max_spd)
spd = max_spd;
}
else {
spd = 0;
}
 

woods

Member
i would start with something like this...

if (mouse_check_button(mb_left)) && !(place_meeting(obj_wall)){
spd += acceleration;
move_towards_point(mouse_x,mouse_y,spd);
.
.
.
}




obj_player step event:
Code:
if place_meeting(x,y,obj_wall)
{
//do stuff
}
 
Top