M
MrSanfrinsisco
Guest
I've been spending the last while trying to create a wall that works fine, I've watched 2 or 3 youtube tutorials but all are giving me the same result regardless; my player gets stuck in the wall and I cannot get out. I want to know what the best way as to go about creating a wall that works fine. I'm not looking for anything extremely complex as I'm still new to this but something that is simple and works without very much problem. Here is my current code:
Code:
//Keyboard Variabls
moveUp = keyboard_check(ord("W"));
moveLeft = keyboard_check(ord("A"));
moveDown = keyboard_check(ord("S"));
moveRight = keyboard_check(ord("D"));
//Player Move Set
var moveLR = moveRight - moveLeft;
var moveUD = moveDown - moveUp;
//Variabls to check Vertical / Horizontal speed
playerHorizontal = moveLR * playerMoveSpeed;
playerVertical = moveUD * playerMoveSpeed;
//Player Movement
if (playerHorizontal < 0 || playerHorizontal > 0) || (playerVertical < 0 || playerVertical > 0) {
sprite_index = spr_player_running;
if (playerHorizontal < 0) {
if (place_meeting(x+playerHorizontal, y, obj_wallLR)) {
playerHorizontal = 0;
} else {
x -= playerMoveSpeed;
image_angle = -90
}
}
if (playerHorizontal > 0) {
if (place_meeting(x+playerHorizontal, y, obj_wallLR)) {
playerHorizontal = 0;
} else {
x += playerMoveSpeed;
image_angle = 90;
}
}
if (playerVertical < 0) {
if (place_meeting(x, y+playerVertical, obj_wallTB)) {
playerVertical = 0;
} else {
y -= playerMoveSpeed;
image_angle = 180;
}
}
if (playerVertical > 0) {
if (place_meeting(x, y+playerVertical, obj_wallTB)) {
playerVertical = 0;
} else {
y += playerMoveSpeed
image_angle = 0;
}
}
} else {
sprite_index = spr_player;
}