Stopped player turning around during wall ride

This commit is contained in:
2025-03-28 14:07:24 +00:00
parent 639cb88e63
commit a972667fe4
4 changed files with 26 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ public partial class PlayerMovement : MonoBehaviour
Collider closest = null;
foreach (Collider collision in m_WallCollisions)
{
{
Vector3 pos = collision.ClosestPoint(transform.position);
Vector3 dif = transform.position - pos;
@@ -53,9 +53,21 @@ public partial class PlayerMovement : MonoBehaviour
// Calculates the foward direction of the wall
Vector3 foward = Vector3.Cross(m_WallNormal, transform.up);
// Flips the foward direction if facing the other direction
if ((m_Orientation.forward - foward).magnitude > (m_Orientation.forward - (-foward)).magnitude)
{ foward = -foward; }
if (m_FirstFrameWallRiding == true)
{
// Resets the tracker
m_FirstFrameWallRiding = false;
// Calculates it should flip the direction of the wall riding depending on the direction the player is looking
bool flip = (m_Orientation.forward - foward).magnitude > (m_Orientation.forward - (-foward)).magnitude;
// Stores it for all the other frames of the current wall ride
m_FlippedWallRideDirectionFirstFrame = flip;
}
// Flips the direction if it did the first frame to stop the direction changing mid wall ride
if (m_FlippedWallRideDirectionFirstFrame == true)
{ foward = -foward; }
// Applies the wall running force to the player
m_Body.AddForce(foward * m_WallRunSpeed * m_Body.mass * 10.0f, ForceMode.Force);