Godot Version
godot 4.3
Question
the title says it all. I had a function that lerps camera values but I updated my project to 4.3 to use jolt and now the camera snaps with no interpolation.
godot 4.3
the title says it all. I had a function that lerps camera values but I updated my project to 4.3 to use jolt and now the camera snaps with no interpolation.
Jolt shouldn’t have interfered with lerping. Lerping is just a math function, has nothing to do with physics.
Show your code please and maybe a short video of before and after conversion.
thats what I thought, but it only changed either when i updated or when i enabled jolt
camera.position = lerp(camera.position, crawlCamPos.position, .1 * delta)
Can you show a video of before and after?
And please share your whole script, not just the line with the lerp. It’s important to understand the context.
Sure!
I can’t put a video up right now, but the camera was moving smoothly, and now it’s snapping to the position
extends RigidBody3D
var curMaxSpeed = 3
@export var walkSpeed = 3
@export var crouchSpeed = 1
@export var sprintSpeed = 6
@export var jumpForce = 10
@export var diveForce = 10
@export var SENSITIVITY = 3.0
@export var CONTROLLER_SENSITIVITY = 10.0
@export var Controller_Smoothing = .5
@export var Controller_resistance = .3
@export var jumpTimerMax = 50
@export var gravity = 50
@export var leanamount = 1.0
@export var toggleSprint = false
var jumpTimer = 50
var crouch = false
var crawl = false
var sprint = false
var moving = false
var canStand = true
var stood = true
var diving = false
var ladder = false
@export var DOUBLETAP_DELAY = .25
var doubletap_time = .25
var last_event = "null"
var rotation_velocity : Vector2
const BOB_FREQUENCY = 2.0
const BOB_AMPLITUDE = 0.1
var t_bob = 0.0
const BASE_FOV = 100.0
const FOV_CHANGE = .5
@onready var camera = $Head/LeanContainer/Camera3D
@onready var head = $Head
@onready var leanContainer = $Head/LeanContainer
@onready var floorCheck = $Checks/FloorCheck
@onready var standCollider = $StandCollider
@onready var crouchCollider = $CrouchCollider
@onready var crawlCollider = $CrawlCollider
@onready var doveCheck = $Checks/doveCheck
@onready var headCheck = $Checks/HeadCheck
@onready var crouchCheck = $Checks/CrouchCheck
@onready var crawlCheck = $Checks/CrawlCheck
@onready var LeanCheck_R = $Head/Leancheck_R
@onready var LeanCheck_L = $Head/Leancheck_L
@onready var CrouchLeanCheck_R = $Head/CrouchLeancheck_R
@onready var CrouchLeanCheck_L = $Head/CrouchLeancheck_L
@onready var standCamPos = $Head/LeanContainer/StandCamPos
@onready var crouchCamPos = $Head/LeanContainer/CrouchCamPos
@onready var crawlCamPos = $Head/LeanContainer/CrawlCamPos
var lean_nagle: float = PI / 8
var tween_duration: float = 0.2
# Called when the node enters the scene tree for the first time.
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _physics_process(delta):
t_bob += delta * linear_velocity.length()
camera.transform.origin = _headbob(t_bob)
var target_fov = BASE_FOV + FOV_CHANGE * linear_velocity.length()
camera.fov = lerp(camera.fov, target_fov, delta * 8.0)
doubletap_time -= delta
jumpTimer -= 1
if jumpTimer<= 0:
moving = false
if moving:
set_linear_velocity(linear_velocity.lerp(Vector3.ZERO, 1))
elif diving:
set_linear_velocity(linear_velocity.lerp(Vector3.ZERO, .01))
else:
var clampVelocity = Vector3(0, 10000, 0)
set_linear_velocity(linear_velocity.clamp(Vector3(0,-10000,0), clampVelocity))
if !ladder:
_crouch(delta)
_crawl()
_move()
_jump()
if jumpTimer<= 0:
linear_velocity.y -= gravity * delta
_controllerCam(delta)
if toggleSprint:
_toggle_sprint()
else:
_sprint()
_ladder()
if floorCheck.is_colliding() == true:
_lean()
func _crouch(delta):
if Input.is_action_just_pressed("Crouch"):
if crouch == true:
if !crouchCheck.has_overlapping_bodies():
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
else:
if crawl:
if !crawlCheck.has_overlapping_bodies():
standCollider.disabled = true
crouchCollider.disabled = false
crawlCollider.disabled = true
crouch = true
crawl = false
else:
standCollider.disabled = true
crouchCollider.disabled = false
crawlCollider.disabled = true
crouch = true
crawl = false
if canStand:
rotation = Vector3.ZERO
axis_lock_angular_x = true
axis_lock_angular_z = true
if stood == false:
position = Vector3(position.x, position.y + 1, position.z)
stood = true
if crouch == false:
if crawl:
camera.position = lerp(camera.position, crawlCamPos.position, .1 * delta)
curMaxSpeed = crouchSpeed
else:
camera.position = lerp(camera.position, standCamPos.position, .1 * delta)
else:
camera.position = lerp(camera.position, crouchCamPos.position, .1 * delta)
curMaxSpeed = crouchSpeed
func _crawl():
if Input.is_action_just_pressed("Crawl"):
if crawl == true:
if !crawlCheck.has_overlapping_bodies() && !crouchCheck.has_overlapping_bodies():
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crawl = false
crouch = false
else:
standCollider.disabled = true
crouchCollider.disabled = true
crawlCollider.disabled = false
crawl = true
crouch = false
if canStand:
rotation = Vector3.ZERO
axis_lock_angular_x = true
axis_lock_angular_z = true
if stood == false:
position = Vector3(position.x, position.y + 1, position.z)
stood = true
func _move():
var move_dir_Y = Input.get_axis("North","South")
var move_dir_X = Input.get_axis("West","East")
if !move_dir_X == 0 || !move_dir_Y == 0:
moving = true
if canStand:
rotation = Vector3.ZERO
axis_lock_angular_x = true
axis_lock_angular_z = true
if stood == false:
position = Vector3(position.x, position.y + 1, position.z)
stood = true
else:
moving = false
if Input.is_action_just_pressed("Jump") && crouch == false && crawl == false:
if last_event == "Jump" and doubletap_time >= 0 && !headCheck.has_overlapping_bodies():
axis_lock_angular_x = false
axis_lock_angular_z = false
apply_impulse(head.basis * (Vector3(move_dir_X, 0, move_dir_Y) * diveForce), Vector3(0,.03,0))
jumpTimer = jumpTimerMax
canStand = false
stood = false
diving = true
last_event = "null"
else:
last_event = "Jump"
doubletap_time = DOUBLETAP_DELAY
if sprint:
camera.rotation.z = camera.rotation.lerp(Vector3(0,0,-move_dir_X) / 5, .1).z
else:
camera.rotation.z = camera.rotation.lerp(Vector3(0,0,0) / 5, .1).z
if !diving:
apply_central_force(head.basis * (Vector3(move_dir_X, 0, move_dir_Y) * curMaxSpeed * 10))
func _lean():
if !crawl:
if crouch:
if !CrouchLeanCheck_R.is_colliding():
if Input.is_action_just_pressed("LeanRight"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, 0.0, -leanamount, tween_duration)
elif Input.is_action_just_released("LeanRight"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, -leanamount, 0.0, tween_duration)
if !CrouchLeanCheck_L.is_colliding():
if Input.is_action_just_pressed("LeanLeft"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, 0.0, leanamount, tween_duration)
elif Input.is_action_just_released("LeanLeft"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, leanamount, 0.0, tween_duration)
else:
if !LeanCheck_R.is_colliding():
if Input.is_action_just_pressed("LeanRight"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, 0.0, -leanamount, tween_duration)
elif Input.is_action_just_released("LeanRight"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, -leanamount, 0.0, tween_duration)
if !LeanCheck_L.is_colliding():
if Input.is_action_just_pressed("LeanLeft"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, 0.0, leanamount, tween_duration)
elif Input.is_action_just_released("LeanLeft"):
var tween: Tween = create_tween()
tween.tween_method(func(angle: float): leanContainer.rotation = leanContainer.basis * Vector3.BACK * angle, leanamount, 0.0, tween_duration)
func _toggle_sprint():
if Input.is_action_just_pressed("Sprint"):
if !sprint:
if crouch:
if !crouchCheck.has_overlapping_bodies():
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
elif crawl:
if !crawlCheck.has_overlapping_bodies() && !crouchCheck.has_overlapping_bodies():
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
else:
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
else:
sprint = false
if sprint:
curMaxSpeed = sprintSpeed
else:
if !crawl && !crouch:
curMaxSpeed = walkSpeed
if !moving && !ladder:
sprint = false
func _sprint():
if Input.is_action_pressed("Sprint"):
if crouch:
if !crouchCheck.has_overlapping_bodies():
curMaxSpeed = sprintSpeed
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
elif crawl:
if !crawlCheck.has_overlapping_bodies() && !crouchCheck.has_overlapping_bodies():
curMaxSpeed = sprintSpeed
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
else:
curMaxSpeed = sprintSpeed
standCollider.disabled = false
crouchCollider.disabled = true
crawlCollider.disabled = true
crouch = false
crawl = false
sprint = true
else:
if !crawl || !crouch:
curMaxSpeed = walkSpeed
sprint = false
func _jump():
if !crawl:
if Input.is_action_just_pressed("Jump") && floorCheck.is_colliding():
linear_velocity.y = jumpForce
jumpTimer = jumpTimerMax
if Input.is_action_pressed("Jump"):
if doveCheck.get_overlapping_bodies().size() > 1 && headCheck.get_overlapping_bodies():
linear_velocity.y = 4
func _controllerCam(delta):
var x = Input.get_axis("Left","Right")
var y = Input.get_axis("Up","Down")
if x != 0:
rotation_velocity.x = rotation_velocity.lerp(Vector2(x,y) * -CONTROLLER_SENSITIVITY /10, (Controller_Smoothing/100)).x
else:
rotation_velocity.x = rotation_velocity.lerp(Vector2.ZERO, (Controller_resistance/100)).x
if y != 0:
rotation_velocity.y = rotation_velocity.lerp(Vector2(x,y) * -CONTROLLER_SENSITIVITY / 10, (Controller_Smoothing/100)).y
else:
rotation_velocity.y = rotation_velocity.lerp(Vector2.ZERO, (Controller_resistance/100)).y
head.rotate_y(deg_to_rad(rotation_velocity.x))
camera.rotate_x(deg_to_rad(rotation_velocity.y))
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-89), deg_to_rad(90))
func _unhandled_input(event):
if event is InputEventMouseMotion:
head.rotate_y(-event.relative.x * SENSITIVITY *.001)
camera.rotate_x(-event.relative.y * SENSITIVITY * .001)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-89), deg_to_rad(90))
func _ladder():
var i = 0
var ladCount = 0
for body in doveCheck.get_overlapping_bodies():
if body.is_in_group("Ladder"):
ladder = true
ladCount += 1
if i == doveCheck.get_overlapping_bodies().size() -1 && ladCount == 0:
ladder = false
i += 1
if ladder:
var move_dir_Y = Input.get_axis("South","North")
if sprint:
position.y += move_dir_Y * .04
else:
position.y += move_dir_Y * .02
gravity_scale = 0
if floorCheck.is_colliding() && move_dir_Y < 0:
ladder = false
apply_impulse(basis.x * -1)
if Input.is_action_just_pressed("Jump"):
apply_impulse(basis.x * -30)
ladder = false
else:
gravity_scale = 1
func _on_dove_check_body_entered(body):
canStand = true
diving = false
func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
var curCamPos
if crouch:
curCamPos = crouchCamPos
elif crawl:
curCamPos = crawlCamPos
else:
curCamPos = standCamPos
pos.y = curCamPos.position.y + (sin(time * BOB_FREQUENCY) * BOB_AMPLITUDE)
pos.x = curCamPos.position.x + (cos(time * BOB_FREQUENCY/2) * BOB_AMPLITUDE)
return pos
I figured it out, the _headbob function was overwritng my lerp. nvm