P
Pitu
Guest
Hello, how would I go on about making dynamic collision checking with lets say my player object, the video shows what i mean.
Also if i were to use for example a jumping sprite, that would extend his arms in mid air but that would cause him to be stuck way more than just that because the collision already happened, so how would i go on about fixing that? (i'm using place_meeting at the moment to collide the player with the walls, no physics)
Code for that player object (and only code im using so far in my entire game):
CREATE EVENT:
STEP EVENT:
PS. Sorry for bad comments in the code, not very efficient programmer. Thanks in advance
Also if i were to use for example a jumping sprite, that would extend his arms in mid air but that would cause him to be stuck way more than just that because the collision already happened, so how would i go on about fixing that? (i'm using place_meeting at the moment to collide the player with the walls, no physics)
Code for that player object (and only code im using so far in my entire game):
CREATE EVENT:
Code:
///Initialize Variables
grav = 1;
spd = 4;
jspd = 20;
hspd = 0;
vspd = 0;
//Stop animation
image_speed = 0;
Code:
//Get the player's input
key_right = keyboard_check(ord('D'));
key_left = keyboard_check(ord('A'));
key_jump = keyboard_check_pressed(ord('W'));
//Check for collisios
if(place_meeting(x, y+2, obj_wall))
{
vspd = 0;
//Jumping
if(key_jump){
vspd = -jspd;
}
} else{
//Move down with gravity
if(vspd < 10){
vspd += grav;
}
}
//Moving to the right
if(key_right){
hspd = spd;
}
//Moving to the left
if(key_left){
hspd = -spd;
}
//Check for not moving
if((!key_right && !key_left) || (key_right && key_left)){
hspd = 0;
}
//Horizontal collisions ADD IN SCRIPT
if(place_meeting(x+hspd, y, obj_wall)){
while(!place_meeting(x+sign(hspd), y, obj_wall)){
x+= sign(hspd);
}
hspd = 0;
}
//Move horizontally
x += hspd;
//Verticle collisions ADD IN SCRIPT
if(place_meeting(x, y+vspd, obj_wall)){
while(!place_meeting(x, y+sign(vspd), obj_wall)){
y+= sign(vspd);
}
vspd = 0;
}
//Move vertically
y += vspd;
//Sprite control
//Walking right
if(hspd > 0){
image_speed = 0.2;
sprite_index = spr_player_right;
}
//Walking left
else if(hspd < 0){
image_speed = 0.2;
sprite_index = spr_player_left;
}
/*Jumping
else if((vspd > 0) || (vspd < 0)){
image_speed = 0.2;
sprite_index = spr_player_jumping;
}*/
else{
image_index = 0;
}
//Audio control
//When walking right
if(hspd > 0){
if !audio_is_playing(aud_walking)
audio_play_sound(aud_walking, 1, true);
}
//When walking left
else if(hspd < 0){
if !audio_is_playing(aud_walking)
audio_play_sound(aud_walking, 1, true);
}
else{
audio_stop_sound(aud_walking);
}
if(vspd > 0){
audio_stop_sound(aud_walking);
}