Improve movement

This commit is contained in:
~erin 2022-05-11 12:30:14 -04:00
parent 5f70906f71
commit 72f25f7960
No known key found for this signature in database
GPG Key ID: DA70E064A8C70F44
1 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,8 @@
extends KinematicBody2D
const MAX_SPEED = 100
const MAX_SPEED = 80
const ACCELERATION = 500
const FRICTION = 500
var velocity = Vector2.ZERO
@ -12,10 +14,11 @@ func _physics_process(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
velocity = input_vector
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
velocity = Vector2.ZERO
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move_and_collide(velocity * delta * MAX_SPEED)
move_and_collide(velocity * delta)