Improved lerp interpolation
This commit is contained in:
parent
2a53a731db
commit
a374acc4f0
@ -44,4 +44,4 @@ func _process(delta):
|
||||
if abs(distance - position.z) < 0.01:
|
||||
return
|
||||
|
||||
position.z = lerpf(position.z, distance, zoom_interpolation * delta)
|
||||
position.z = Math.dampf(position.z, distance, zoom_interpolation * delta)
|
||||
|
@ -8,7 +8,7 @@ func _process(delta):
|
||||
return
|
||||
|
||||
if interpolate:
|
||||
position = lerp(position, Global.player.position, speed * delta)
|
||||
position = Math.damp(position, Global.player.position, speed * delta)
|
||||
else:
|
||||
position = Global.player.position
|
||||
|
||||
|
@ -23,7 +23,7 @@ func _process(delta):
|
||||
if !collected_by:
|
||||
return
|
||||
|
||||
global_position = lerp(global_position, Global.player.global_position + Vector3.UP, 1.0 * delta)
|
||||
global_position = Math.damp(global_position, Global.player.global_position + Vector3.UP, 1.0 * delta)
|
||||
|
||||
func on_body_entered(body: Node3D):
|
||||
if body is Player:
|
||||
|
10
client/math/Math.gd
Normal file
10
client/math/Math.gd
Normal file
@ -0,0 +1,10 @@
|
||||
class_name Math
|
||||
|
||||
static func damp(from: Variant, to: Variant, weight: float, smoothing: float = 0.75):
|
||||
return lerp(from, to, 1 - exp(-smoothing * weight))
|
||||
|
||||
static func dampf(from: float, to: float, weight: float, smoothing: float = 0.75):
|
||||
return lerpf(from, to, 1 - exp(-smoothing * weight))
|
||||
|
||||
static func damp_angle(from: float, to: float, weight: float, smoothing: float = 0.75):
|
||||
return lerp_angle(from, to, 1 - exp(-smoothing * weight))
|
@ -15,5 +15,5 @@ func _ready():
|
||||
|
||||
func _process(delta: float):
|
||||
var time := interpolation_speed * delta
|
||||
player.position.x = lerpf(player.position.x, server_position.x, time)
|
||||
player.position.z = lerpf(player.position.z, server_position.z, time)
|
||||
player.position.x = Math.dampf(player.position.x, server_position.x, time)
|
||||
player.position.z = Math.dampf(player.position.z, server_position.z, time)
|
@ -12,7 +12,7 @@ func _ready():
|
||||
owner.controller.direction_changed.connect(on_direction_changed)
|
||||
|
||||
func _process(delta):
|
||||
root.rotation.y = lerp_angle(root.rotation.y, angle, rotation_speed * delta)
|
||||
root.rotation.y = Math.damp_angle(root.rotation.y, angle, rotation_speed * delta)
|
||||
|
||||
func on_direction_changed(new_direction: Vector3):
|
||||
direction = new_direction
|
||||
|
Loading…
Reference in New Issue
Block a user