My Kinematicbody2d doesnt move up

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jabba

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 _fixed_process(delta: float) → void:

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

direction += velocity * delta * speed

:bust_in_silhouette: Reply From: njamster

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.

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

jabba | 2020-06-20 11:25