Line 41:Too few arguments for “lerp()” call. Expected at least 3 but received 2.
Line 5:The default value is using “$” which won’t return nodes in the scene tree before “_ready()” is called. Use the “@onready” annotation to solve this. (Warning treated as error.)
@onready var head: Node3D = $Head
@onready var standing_collision_shape: CollisionShape3D = $StandingCollisionShape
@onready var crouching_collison_shape: CollisionShape3D = $CrouchingCollisonShape
var camera = $Head/Camera3D
var current_speed = 5.0
var direction = Vector3.ZERO
var lerp_speed = 10.0
const walking_speed = 5.0
const springing_speed = 8.0
const crouching_speed = 3.0
const mouse_sense = 0.4
const JUMP_VELOCITY = 4.5
var crouching_depth = -0.5
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x * mouse_sense))
head.rotate_x(deg_to_rad(-event.relative.y * mouse_sense))
head.rotation.x = clamp(head.rotation.x,deg_to_rad(-89), deg_to_rad(89))
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("Crouch"):
current_speed = crouching_speed
head.position.y = lerp(head.position.y,1.8 + crouching_depth, delta*lerp_speed)
standing_collision_shape.disabled = true
crouching_collison_shape.disabled = false
else:
standing_collision_shape.disabled = false
crouching_collison_shape.disabled = true
head.position.y = lerp(head.position.y,1.8,delta*lerp_speed)
if Input.is_action_pressed("Sprnt"):
current_speed = springing_speed
camera.fov = lerpf(camera.fov (75 if Input.is_action_pressed("sprint") else 65), delta*10.0)
else:
current_speed = walking_speed
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("Left", "Right", "Forward", "Backward")
direction = lerp(direction,(transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized(),delta*lerp_speed)
if direction:
velocity.x = direction.x * current_speed
velocity.z = direction.z * current_speed
else:
velocity.x = move_toward(velocity.x, 0, current_speed)
velocity.z = move_toward(velocity.z, 0, current_speed)
move_and_slide()
I fixed the $head Error but now it comes up with a diffrent error
ine 41:Name “fov” called as a function but is a “float”.
Line 41:Too few arguments for “lerp()” call. Expected at least 3 but received 2.