Skip to content

Commit

Permalink
fix(PlayerControllerRBBase): Unity 6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGadget1024 committed Oct 24, 2024
1 parent 01b9260 commit 19296d5
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
using UnityEngine.Serialization;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -479,15 +483,23 @@ 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
if (runtimeData.groundState != GroundState.Grounded)
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
}
}
}

0 comments on commit 19296d5

Please sign in to comment.