# what is the difference between the linear_interpolate functon and the lerp function?

Attention Topic was automatically imported from the old Question2Answer platform.

In Garbaj’s tutorial on making a better fps controller he uses this code:

``````extends KinematicBody

var speed = 15
var h_acceleration = 8
var air_acceleration = 1
var normal_acceleration = 6
var gravity = 30
var jump = 10

var full_contact = false

var mouse_sensetivity = 0.3

var direction = Vector3()
var h_velocity = Vector3()
var movement = Vector3()
var gravity_vec = Vector3()

onready var ground_check = \$ground_check

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):

if event is InputEventMouseMotion:

func _physics_process(delta):

direction = Vector3()

if ground_check.is_colliding():
full_contact = true
else:
full_contact = false

if not is_on_floor():
gravity_vec += Vector3.DOWN * gravity * delta
h_acceleration = air_acceleration
elif is_on_floor() and full_contact:
gravity_vec = -get_floor_normal() * gravity
h_acceleration = normal_acceleration
else:
gravity_vec = get_floor_normal()
h_acceleration = normal_acceleration

if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()):
gravity_vec = Vector3.UP * jump

if Input.is_action_pressed("move_forward"):
direction += transform.basis.z
elif Input.is_action_pressed("move_backward"):
direction -= transform.basis.z
if Input.is_action_pressed("move_left"):
direction += transform.basis.x
elif Input.is_action_pressed("move_right"):
direction -= transform.basis.x

direction = direction.normalized()
h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
movement.z = h_velocity.z + gravity_vec.z
movement.x = h_velocity.x + gravity_vec.x
movement.y = gravity_vec.y

move_and_slide(movement,Vector3.UP)
``````

I understand it pretty well, but I’m having trouble with this section:

``````h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
movement.z = h_velocity.z + gravity_vec.z
movement.x = h_velocity.x + gravity_vec.x
movement.y = gravity_vec.y
``````

My original thought was that`h_velocity.linear_interpolate()` is the same as using a `lerp` function,but that doesn’t make sense. If that’s true, I think what his function would be doing is taking the movement of the character and lerping it to h_acceleration, which is 8. That would make zero sense. What is this code actually doing? Thanks.

so far all I’ve found is this link.

Millard | 2020-11-17 19:12