![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | CynicalKazu |
I am working on a Space Invaders clone type of game. I used “move_and_slide” as the player’s movement function. The problem is that diagonal input (like UP and RIGHT pressed together) don’t seem to do anything. Please help as I want 8-way movement in my game. My code:
func _physics_process(delta):
var DOWN = Input.is_action_pressed("ui_down")
var UP = Input.is_action_pressed("ui_up")
var LEFT = Input.is_action_pressed("ui_left")
var RIGHT = Input.is_action_pressed("ui_right")
if DOWN:
velocity = Vector2(0, speed)
move_and_slide(velocity)
elif UP:
velocity = Vector2(0, -speed)
move_and_slide(velocity)
elif RIGHT:
velocity = Vector2(speed, 0)
move_and_slide(velocity)
elif LEFT:
velocity = Vector2(-speed, 0)
move_and_slide(velocity)