Search code examples
game-enginegodot

2D movement how to fix?


I asked this question before and got a answer but that answer didnt work nor did the guy respond so here is my last effort, The kinematic body isnt moving yes i added controls to the project setting, yes there are no errors. I dont know what to do. `

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()

``


Solution

  • You've created a Vector called motion and set it's values, however you never actually do anything with that data.

    It's best to use something like move and slide to alter the position of a kinematic body.

    However, using what you have, you can add your motion values to the global_transform of the node which would have a similar effect.