0 votes

I am working on a Space Invaders clone type of game. I used "moveandslide" 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 physicsprocess(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)
in Engine by (44 points)

1 Answer

0 votes
Best answer

Never mind, it was a noob mistake. I had used elif so two inputs at the same time were never checked for. I changed all elifs to if and now it works.

by (44 points)

If that's what you want for movement then don't use any else ifs

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.