My character is a KinematicBody2D, and I use a joysticks Vector2 to move. I can't figure out/fix a constant speed. When moving up I move very fast, while moving down I move very slow. Left/Right is somewhere in the middle.
Here is my code and some print outputs:
var velocity = Vector2.ZERO
const ACCELERATION = 1000000000000
const MAX_SPEED = 420
func _process(delta):
if leftJoyStickPosition != null:
var input_vector = Vector2.ZERO
input_vector.x = leftJoyStickPosition.x
input_vector.y = (leftJoyStickPosition.y) * -1
if input_vector != Vector2.ZERO:
velocity += input_vector * delta * ACCELERATION
velocity = velocity.clamped(MAX_SPEED)
else:
velocity = velocity.linear_interpolate(Vector2.ZERO, 0.2)
velocity = move_and_slide(velocity)
Here is leftJoyStickPosition
printed:
(0.012194, 0.999926) #when pulling straight up
(-0.023615, -0.999721) #when pulling straight down
Here is velocity printed, right before move_and_slide
:
(0, -420) #when pulling straight up
(0, 420) #when pulling straight down
Help is very much appreciated, this is my first game.