From 19296d5d21e484b1c6ce1df5ed7d05a4a7021f06 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Thu, 24 Oct 2024 02:28:54 -0400 Subject: [PATCH] fix(PlayerControllerRBBase): Unity 6 compatibility --- .../PlayerControllerRB/PlayerControllerRBBase.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Examples/_Common/Controllers/PlayerControllerRB/PlayerControllerRBBase.cs b/Assets/Mirror/Examples/_Common/Controllers/PlayerControllerRB/PlayerControllerRBBase.cs index e95a4d3eb..36c9ce24b 100644 --- a/Assets/Mirror/Examples/_Common/Controllers/PlayerControllerRB/PlayerControllerRBBase.cs +++ b/Assets/Mirror/Examples/_Common/Controllers/PlayerControllerRB/PlayerControllerRBBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using UnityEngine; using UnityEngine.Serialization; @@ -335,7 +335,11 @@ void FixedUpdate() runtimeData.groundState = GroundState.Falling; // Update velocity for diagnostics +#if UNITY_6000_0_OR_NEWER + runtimeData.velocity = Vector3Int.FloorToInt(rigidBody.linearVelocity); +#else runtimeData.velocity = Vector3Int.FloorToInt(rigidBody.velocity); +#endif } void HandleOptions() @@ -479,7 +483,11 @@ void ApplyMove(float fixedDeltaTime) rigidBody.MovePosition(rigidBody.position + runtimeData.direction * fixedDeltaTime); // Handle vertical movement (jumping and gravity) +#if UNITY_6000_0_OR_NEWER + Vector3 verticalMovement = rigidBody.linearVelocity; +#else Vector3 verticalMovement = rigidBody.velocity; +#endif verticalMovement.y = runtimeData.jumpSpeed; // Apply gravity @@ -487,7 +495,11 @@ void ApplyMove(float fixedDeltaTime) verticalMovement.y += Physics.gravity.y * fixedDeltaTime; // Apply vertical movement +#if UNITY_6000_0_OR_NEWER + rigidBody.linearVelocity = new Vector3(rigidBody.linearVelocity.x, verticalMovement.y, rigidBody.linearVelocity.z); +#else rigidBody.velocity = new Vector3(rigidBody.velocity.x, verticalMovement.y, rigidBody.velocity.z); +#endif } } }