mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-04 01:49:07 +00:00
Now able to look any direction during wall ride
Also made a key bind for wallride
This commit is contained in:
@@ -2,11 +2,56 @@ using UnityEngine;
|
||||
|
||||
public partial class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
bool GetNormalOfClosestCollider(out Vector3 normal)
|
||||
{
|
||||
Debug.Log(m_WallCollisions.Count);
|
||||
|
||||
float dist = Mathf.Infinity;
|
||||
Collider closest = null;
|
||||
|
||||
foreach (Collider collision in m_WallCollisions)
|
||||
{
|
||||
Vector3 pos = collision.ClosestPoint(transform.position);
|
||||
Vector3 dif = transform.position - pos;
|
||||
|
||||
float distance = dif.magnitude;
|
||||
|
||||
dist = Mathf.Min(dist, distance);
|
||||
|
||||
if (dist == distance)
|
||||
{
|
||||
closest = collision;
|
||||
}
|
||||
}
|
||||
|
||||
if (dist > m_WallCheckDistance)
|
||||
{
|
||||
normal = Vector3.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 point = closest.ClosestPoint(transform.position);
|
||||
Vector3 dir = point - transform.position;
|
||||
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, dir.normalized, out hit, (m_WallCheckDistance * 2.0f) + 1.0f, m_GroundMask))
|
||||
{
|
||||
normal = hit.normal;
|
||||
return true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Debug.LogError("SOMETHING WENT WRONG");
|
||||
normal = Vector3.zero;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWallRunState()
|
||||
{
|
||||
// Calculates the foward direction of the wall
|
||||
Vector3 normal = m_HitRhsWall ? m_RhsWall.normal : m_LhsWall.normal;
|
||||
Vector3 foward = Vector3.Cross(normal, transform.up);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user