Attention | Topic was automatically imported from the old Question2Answer platform. | |
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)