This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I wrote some code of basic movements for a 2D kinematic body. I did that and its not moving and stuck at the top of the debug screen.

    extends KinematicBody2D

var movespeed = 500

func _ready():
    pass # Replace with function body.
func _physics_process(delta):
    var motion = Vector2()

    if Input.is_action_pressed("up"):
        motion.y -= 1
        if Input.is_action_pressed("down"):
            motion.y += 1
    if Input.is_action_pressed("left"):
        motion.x += 1
    if Input.is_action_pressed("right"):
        motion.x -= 1

    motion = motion.normalized()
    motion = move_and_slide(motion * movespeed)

Does anybody know where I went wrong?

Godot version 3.2
in Engine by (19 points)

2 Answers

0 votes
Best answer

You're checking if up and down are being pressed at the same time due to the indentation, bring the 'down' if statement to the left. Also it's not necessary to have motion = move_and_slide here.

by (3,259 points)
selected by

Oh ok thanks so much

tried it out and it didnt work

Just checking, is "down" in your input map? The default is "ui_down".

0 votes

I don't see an error in the code, but the problem can be that there is a conflict between the Input.is_action_pressed and the input map.

by (353 points)

Wdym by conflict? like there's a error? there's no error appearing on my screen at least

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.