0 votes

im new to godot just started learning , i tried to make a movement for the player but the scrips always runs the last if statlment ignoring the rest before

this is the scritp i had

extends KinematicBody2D

export(int) var speed = 100

var movement_direction := Vector2.ZERO

func _process(delta):

if Input.is_action_pressed("right"):
if Input.is_action_pressed("left"):

    movement_direction = movement_direction.normalized()
Godot version version 3.3.3
in Engine by (14 points)

In future, when pasting code here, use the "Code Sample" button to format it correctly.

1 Answer

+1 vote

Because of the way you've pasted your code it's hard to tell if your formatting is correct. However, it does look like those last two lines are indented so that they are under the second if statement. That is why pressing "right" won't do anything.

Also, if you're moving a KinematicBody2D with move_and_slide() you should be using _physics_process() rather than _process().

by (21,920 points)
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 Frequently asked questions and 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 [email protected] with your username.