Improved movement interpolation

This commit is contained in:
2024-02-23 20:13:46 +01:00
parent 7926b7a80e
commit fcee55d9a4
10 changed files with 48 additions and 31 deletions

View File

@ -0,0 +1,13 @@
class_name BotController
extends Controller
var turn: float
var turn_speed: float = 2.0
func _process(delta):
if (Time.get_ticks_msec() / 1000) % 2 == 0:
direction_changed.emit(Vector3.ZERO)
else:
turn += turn_speed * delta
var direction := Vector3.RIGHT.rotated(Vector3.UP, turn)
direction_changed.emit(direction)

View File

@ -1,7 +1,7 @@
class_name ProxyController
extends Controller
@export var interpolation_speed: float = 10.0
@export var interpolation_speed := 5.0
var player: Player
var server_position: Vector3
@ -13,7 +13,7 @@ func _init(new_player: Player):
func _ready():
server_position = player.position
func _process(delta: float):
func _physics_process(delta: float):
var time := interpolation_speed * delta
player.position.x = Math.dampf(player.position.x, server_position.x, time)
player.position.z = Math.dampf(player.position.z, server_position.z, time)

View File

@ -3,7 +3,7 @@ extends Node
@export var move_speed := 4.5
@export var jump_velocity := 4.5
@export var deceleration := 0.75
@export var deceleration_speed := 20
var body: Character
var direction: Vector3
@ -20,8 +20,8 @@ func _physics_process(delta):
body.velocity.x = direction.x * move_speed
body.velocity.z = direction.z * move_speed
else:
body.velocity.x *= deceleration
body.velocity.z *= deceleration
body.velocity.x = Math.dampf(body.velocity.x, 0, deceleration_speed * delta)
body.velocity.z = Math.dampf(body.velocity.z, 0, deceleration_speed * delta)
if !body.is_on_floor():
body.velocity.y -= gravity * delta

View File

@ -2,7 +2,7 @@ class_name RotationComponent
extends Node
@export var root: Node3D
@export var rotation_speed: float = 20.0
@export var rotation_speed: float = 15.0
var direction: Vector3
var angle: float