lerp() function not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Liam Steyn

I was trying to make the car movement a bit smother because now at the moment all it does is stops immediately. So I used the lerp() function but it doesn’t work? I have no clue as to what causes this but your help would be heavily appreciated.

extends KinematicBody2D

onready var speed = 200

export var rotation_speed = 0.5

var shift = false
var rotation_dir = 0
var velocity = Vector2()

func _physics_process(delta):

rotation_dir = 0
velocity = Vector2()

if Input.is_action_pressed("shift up"):
	speed = 500
elif Input.is_action_pressed("shift down"):
	speed = 200

if Input.is_action_pressed("forward"):
	velocity += Vector2(-speed, 0).rotated(rotation)
elif Input.is_action_pressed("back"):
	velocity += Vector2(speed, 0).rotated(rotation)
else:
	speed = 200
	velocity.y = 0
	#velocity = lerp(velocity.y, 0, 0.2)

if Input.is_action_pressed("left"):
	rotation_dir -= 10
if Input.is_action_pressed("right"):
	rotation_dir += 10

if velocity.y == 0:
	rotation_speed = 0
else:
	rotation_speed = 0.5

rotation += rotation_dir * rotation_speed * delta

move_and_slide(velocity)

velocity.y = lerp(velocity.y, 0, 0.2)
:bust_in_silhouette: Reply From: Inces

I didn’t even get to the end of code and I see You made an IF statement which makes velocity.y 0 immadietely when FORWARD or BACKWARD are not pressed. So Your lerp function doesn’t even get chance to resolve .

OMG Thank you so much!! I don’t notice these things bc I really don’t know how to code that well I just wanted to see if I could make a game.

Liam Steyn | 2021-10-21 10:10