Made wall-riding able to turn corners

Also changed air drag
This commit is contained in:
2025-03-28 14:29:03 +00:00
parent a972667fe4
commit 01e700a00e
5 changed files with 234 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ public partial class PlayerMovement : MonoBehaviour
[SerializeField] float m_WallRunSpeed;
[SerializeField] float m_WallCheckDistance;
[SerializeField] float m_DistanceOfFloorToWallRide;
[SerializeField] float m_WallRideDrag;
[Header("KeyBinds")]
[SerializeField] KeyCode m_JumpKey;
@@ -68,6 +69,7 @@ public partial class PlayerMovement : MonoBehaviour
// Wall riding trackers
bool m_FirstFrameWallRiding = true;
bool m_FlippedWallRideDirectionFirstFrame = false;
Vector3 m_LastWallNormal;
// Raycast hit objects
RaycastHit m_GroundHit;
@@ -91,6 +93,7 @@ public partial class PlayerMovement : MonoBehaviour
// Creates the wall collider
m_WallCollider = gameObject.AddComponent<BoxCollider>();
m_WallCollider.size = new Vector3(m_WallCheckDistance * 2, 0.2f, m_WallCheckDistance * 2);
m_WallCollider.center = new Vector3(0.0f, 0.5f, 0.5f);
m_WallCollider.providesContacts = true;
m_WallCollider.isTrigger = true;

View File

@@ -18,14 +18,14 @@ public partial class PlayerMovement : MonoBehaviour
Vector3 vel = m_Body.velocity;
bool canSlide = !(Mathf.Abs(vel.x) < m_SlideRequiredSpeed && Mathf.Abs(vel.z) < m_SlideRequiredSpeed);
// Checks if the player is in the wall running state
if (GetNormalOfClosestCollider(out m_WallNormal) && m_WallRunKeyPressed)
{ m_State = PlayerState.WALL_RUNNING; }
// Checks if the player is in the wall riding state
else if (m_SlidingKeyPressed && (canSlide || m_OnSlope) && m_Grounded)
if (m_SlidingKeyPressed && (canSlide || m_OnSlope) && m_Grounded)
{ m_State = PlayerState.SLIDING; }
// Checks if the player is in the wall running state
else if (GetNormalOfClosestCollider(out m_WallNormal) && m_WallRunKeyPressed)
{ m_State = PlayerState.WALL_RUNNING; }
// Defaults to ruuning
else { m_State = PlayerState.RUNNING; }

View File

@@ -24,6 +24,10 @@ public partial class PlayerMovement : MonoBehaviour
m_Body.drag = m_SlideDrag;
break;
case PlayerState.WALL_RUNNING:
m_Body.drag = m_WallRideDrag;
break;
default:
// Applies different drag depending on if the player is on the ground or not
if (m_Grounded)

View File

@@ -4,8 +4,6 @@ public partial class PlayerMovement : MonoBehaviour
{
bool GetNormalOfClosestCollider(out Vector3 normal)
{
Debug.Log(m_WallCollisions.Count);
float dist = Mathf.Infinity;
Collider closest = null;
@@ -53,7 +51,7 @@ public partial class PlayerMovement : MonoBehaviour
// Calculates the foward direction of the wall
Vector3 foward = Vector3.Cross(m_WallNormal, transform.up);
if (m_FirstFrameWallRiding == true)
if (m_FirstFrameWallRiding == true || m_LastWallNormal != m_WallNormal)
{
// Resets the tracker
m_FirstFrameWallRiding = false;
@@ -74,5 +72,8 @@ public partial class PlayerMovement : MonoBehaviour
// Removes any vertical velocity the player may have
m_Body.velocity = new Vector3(m_Body.velocity.x, 0.0f, m_Body.velocity.z);
// Sets the last wall normal to the current normal for later use
m_LastWallNormal = m_WallNormal;
}
}