25 lines
765 B
GDScript3
Raw Normal View History

2024-02-07 22:04:19 +00:00
class_name ProxyController
extends Controller
2024-02-27 20:05:55 +00:00
@export var interpolation_speed := 20.0
2024-02-07 22:04:19 +00:00
2024-02-15 17:06:44 +00:00
var player: Player
2024-02-27 20:05:55 +00:00
var movement: MovementComponent
2024-02-07 22:04:19 +00:00
var server_position: Vector3
func _init(new_player: Player):
player = new_player
2024-02-15 15:28:27 +00:00
name = "Controller"
2024-02-27 20:05:55 +00:00
process_physics_priority = 1
2024-02-07 22:04:19 +00:00
func _ready():
2024-02-27 20:13:27 +00:00
movement = player.movement
2024-02-07 22:04:19 +00:00
server_position = player.position
2024-02-23 19:13:46 +00:00
func _physics_process(delta: float):
2024-02-27 20:05:55 +00:00
if absf(server_position.x - movement.physics_position.x) < 0.001 && absf(server_position.z - movement.physics_position.z) < 0.001:
2024-02-26 22:50:56 +00:00
return
2024-02-27 20:05:55 +00:00
2024-02-15 17:06:44 +00:00
var time := interpolation_speed * delta
2024-02-27 20:05:55 +00:00
movement.physics_position.x = Math.dampf(movement.physics_position.x, server_position.x, time)
movement.physics_position.z = Math.dampf(movement.physics_position.z, server_position.z, time)