E
EAE01120
Guest
Hey all! I am following a Shaun Spalding tutorial on YouTube, and I have came across the same issue I did on another project following the same video. The moment I add a collision script, my character is stuck in place even when it is not touching something it can collide with. Here is my Player Step Code-
And here is my PlayerCollision script-
GML:
//MOVE AND ANIMATION START
keyLeft = keyboard_check(vk_left);
keyRight = keyboard_check(vk_right);
keyUp = keyboard_check(vk_up);
keyDown = keyboard_check(vk_down);
keyUse = keyboard_check_pressed(vk_space);
inputDirection = point_direction(0,0,keyRight-keyLeft,keyDown-keyUp);
inputMagnitude = (keyRight - keyLeft != 0) || (keyDown - keyUp != 0);
hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);
PlayerCollision();
var _oldSprite = sprite_index;
if (inputMagnitude != 0)
{
direction = inputDirection
sprite_index = spriteRun;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame = 0;
playerAnimateSprite();
//END
Code:
function PlayerCollision(){
var _collision = false;
if (tilemap_get_at_pixel(collisionMap, x + hSpeed, y))
{
x -= x mod TILE_SIZE;
if (sign(hSpeed) == 1) x += TILE_SIZE - 1;
hSpeed = 0;
_collision = true;
}
x += hSpeed;
if (tilemap_get_at_pixel(collisionMap, x , y + vSpeed))
{
y -= y mod TILE_SIZE;
if (sign(vSpeed) == 1) y += TILE_SIZE - 1;
vSpeed = 0;
_collision = true;
}
y += vSpeed;
It is currently 2 in the morning where I am so I will get to what responses I can in the morning. Thanks for your help!
return _collision;
}