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:

func fixedprocess(delta: float) -> void:

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

direction += velocity * delta * speed

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,251 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 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.