Im making platformer game. When i press left or right arrow it goes ok but when i stop pressing it goes crazy.
This is my print output.
-11000
484000
-21296000
937024000
-41229058048
1814078554112
-79819459002368
3512056229658624
-154530466588786690
6799340323748184100
-299170956652734050000
13163521811245322000000
-579194977709192660000000
25484578154513349000000000
-1121321420351843300000000000
49338142200333199000000000000
-2170878219035728900000000000000
95518641033109161000000000000000
-4202820050714298200000000000000000
184924077279668960000000000000000000
-8136659400305434300000000000000000000
1.#INF
nan
nan
This is the code.
extends KinematicBody2D
const UP = Vector2.UP
export var speed := 250.0
export var acc := 1000.0
export var friction := 0.2
var motion : Vector2 = Vector2.ZERO
func _physics_process(delta):
var x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if x != 0:
motion.x += x * acc * delta
motion.x = clamp(motion.x, -speed, speed)
else:
motion.x = lerp(motion.x, 0, friction)
print(motion.x)
motion = move_and_slide(motion, UP)