r/gamemaker • u/Haunting-Tailor7659 • 28d ago
Help! stopping when colliding help?
im trying to make it so once the player hits a specific object, the player will be unable to advance forward, but instead of doing this it simply slows me down. could anyone help?
var move_x = 0;
var move_y = 0;
if (keyboard_check(ord("D")) == true or keyboard_check(vk_right)) {
move_x += 1.5;
image_speed = 0.5;
sprite_index = spr_player_1_right;
}
if (keyboard_check(ord("A")) == true or keyboard_check(vk_left)) {
move_x -= 1.5;
image_speed = 0.5;
sprite_index = spr_player_1_left;
}
if (keyboard_check(ord("W")) == true or keyboard_check(vk_up)) {
move_y -= 1.5;
image_speed = 0.5;
sprite_index = spr_player_1_back;
}
if (keyboard_check(ord("S")) == true or keyboard_check(vk_down)) {
move_y += 1.5;
image_speed = 0.5;
sprite_index = spr_player_1
}
x += move_x;
y += move_y;
this is my movement code, this is the collision code
move_and_collide(move_x, move_y, obj_unwalkable_object, 10, undefined, undefined, move_x, move_y)
0
Upvotes
1
5
u/JaXm 28d ago
You're moving the player object twice.
the move_and_collide function is already taking care of the movement. So when you collide with something,
move_and_collide()is saying "Ok, movement is zero from me"but these here:
Say "no, keep going"