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"):
    movement_direction.x=1
if Input.is_action_pressed("left"):
    movement_direction.x=-1





    movement_direction = movement_direction.normalized()
    move_and_slide(movement_direction*speed)
Godot version version 3.3.3
in Engine by (12 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 (20,479 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 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.