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:
|
if abs(distance - position.z) < 0.01:
|
||||||
return
|
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
|
return
|
||||||
|
|
||||||
if interpolate:
|
if interpolate:
|
||||||
position = lerp(position, Global.player.position, speed * delta)
|
position = Math.damp(position, Global.player.position, speed * delta)
|
||||||
else:
|
else:
|
||||||
position = Global.player.position
|
position = Global.player.position
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func _process(delta):
|
|||||||
if !collected_by:
|
if !collected_by:
|
||||||
return
|
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):
|
func on_body_entered(body: Node3D):
|
||||||
if body is Player:
|
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):
|
func _process(delta: float):
|
||||||
var time := interpolation_speed * delta
|
var time := interpolation_speed * delta
|
||||||
player.position.x = lerpf(player.position.x, server_position.x, time)
|
player.position.x = Math.dampf(player.position.x, server_position.x, time)
|
||||||
player.position.z = lerpf(player.position.z, server_position.z, 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)
|
owner.controller.direction_changed.connect(on_direction_changed)
|
||||||
|
|
||||||
func _process(delta):
|
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):
|
func on_direction_changed(new_direction: Vector3):
|
||||||
direction = new_direction
|
direction = new_direction
|
||||||
|
Loading…
Reference in New Issue
Block a user