Hello, I was programming a platforming game in Game Maker v1.3 and whenever the player collides with a block the game oddly crashes. I've made sure it didn't just get stuck and become unresponsive by adding an animated sprite in the corner of the screen. The sprite stops moving, and when I exit the game the game window closes by I have to manually stop running the game. This is the code:
///Movement - Player
//Initiate Input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord('Z'));
//React to Input
dir = key_right + key_left;
hsp = dir * movespeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x, y+1, obj_block)) vsp = key_jump * -jumpspeed;
//Horizontal Collision
if (place_meeting(x + hsp, y, obj_block))
{
while(!place_meeting(x + sign(hsp), y, obj_block))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x, y + vsp, obj_block))
{
while(!place_meeting(x, y + sign(vsp), obj_block))
{
y += sign(hsp);
}
vsp = 0;
}
y += vsp;
Here's also the code for initiating the variables:
///Initiate Variables - Player
hsp = 0;
vsp = 0;
grav = 0.5;
jumpspeed = 7;
movespeed = 5;
dir = 0;
I'd also like to note that the first code segment is located in the Step event of the "obj_player" object, and the second code segment is located in the Create event of the same object. I hope someone can find the solution to this problem, and I appreciate any help I can get. Thanks!