G
gbcd
Guest
Whenever I press any other key besides the WASD keys I coded in, my character suddenly faces right. And when I keep whatever key pressed, his right direction walking animation starts playing, but he stays in place.
Please forgive my noob codes:
Any help is appreciated. Thank you.
Please forgive my noob codes:
GML:
move_up = keyboard_check(ord("W"))
move_left = keyboard_check(ord("A"))
move_down = keyboard_check(ord("S"))
move_right = keyboard_check(ord("D"))
if(keyboard_check(vk_nokey))
{
image_index = 0
}
else
{
horizontal_input = move_right - move_left
vertical_input = move_down - move_up
sprite_direction = point_direction(0, 0, horizontal_input, vertical_input)
move_to_x = lengthdir_x(move_speed, sprite_direction)
move_to_y = lengthdir_y(move_speed, sprite_direction)
if(move_right and place_free(x + collision_speed, y)) or (move_left and place_free(x - collision_speed, y))
{
x += move_to_x
}
if(move_up and place_free(x, y - collision_speed)) or (move_down and place_free(x, y + collision_speed))
{
y += move_to_y
}
switch(sprite_direction)
{
case 0: sprite_index = sWalkingRight break
//case 45: break
case 90: sprite_index = sWalkingUp break
//case 135: break
case 180: sprite_index = sWalkingLeft break
//case 225: break
case 270: sprite_index = sWalkingDown break
//case 315: break
}
}