0 votes

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)
Godot version 3.2.3-stable
in Engine by (24 points)

1 Answer

+1 vote

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 .

by (2,352 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.