#Why isn't my movement working?

1 messages · Page 1 of 1 (latest)

clear light
#

Instead of having multiple if statements, you can do this:

var direction : Vector2 = Input.get_vector("left", "right", "up", "down")

Also assuming this script extends CharacterBody2D, you need to manipulate the built in velocity variable which move_and_slide() uses.
In my game i also have acceleration, which i just set to an absurdly high number to get snappier feeling movement.

var accel : int = 999999
const speed : int = 300
velocity.x = move_toward(velocity.x, speed * direction.x, accel)
velocity.y = move_toward(velocity.y, speed * direction.y, accel)
move_and_slide()
cyan sentinel
#

As the comment says. _ready() is only called once when the node enters the scene.

You need to keep executing the movement code for it to keep working.

Also, you have a "movement" variable, but you're not using it for anything.

Movement code should also be in _physics_process().
Running move_and_slide() repeatedly per frame can cause issues too.

clear light
#

Lol, how did i completely miss that? Of course, john_movement() should be in func _physics_process(delta)