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

Hi All,

Can anyone tell me why my Kinematicbody2d doesnt want to move up, I wrote the following code:

extends KinematicBody2D

export var speed = 200
var velocity = Vector2()
var direction = Vector2()

func _ready() -> void:
pass

func fixedprocess(delta: float) -> void:

if Input.is_action_just_pressed("MoveUp"):
    velocity.y += 1


direction += velocity * delta * speed

move_and_slide(direction)
in Engine by (29 points)

1 Answer

0 votes

There is no _fixed_process-function in Godot 3.X anymore, use _physics_process! Also make sure that you defined an InputAction named "MoveUp" or use "ui_up" (that will be available by default). Lastly, be aware that in Godot the positive y-axis points down, not up (like you may be used to from Mathematics). So currently your character will move *down* when you press "MoveUp", not up (as the name suggests).

Also when you post a question, please make sure that your code is formatted properly (each line has to start with 4 spaces, each additional 4 spaces equal an indentation layer). If you don't, underscores are interpreted as markdown and indentation is lost, which makes your script a lot harder to read for others trying to help you.

by (10,634 points)

Thanq very much, it worked indeed.
Also Thanks for the tip to format the code properly!

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.