diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs index 0bd981d..c0b7476 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs @@ -139,8 +139,8 @@ public class dAerialStateManager : NetworkBehaviour //Grapple Variables hookPoints = GameObject.FindGameObjectsWithTag("HookPoint"); - lastPos = transform.position; //// + lastPos = transform.position; } void Update(){ diff --git a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs index 2bee2a1..600a6c1 100644 --- a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs +++ b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs @@ -62,16 +62,23 @@ public class AerialStateManager : NetworkBehaviour //Ground Check public bool isGrounded; // is player grounded public float groundCheckDistance = 0.05f; // offset distance to check ground - private float groundSlantDistance = .05f; + private float groundSlantDistance = .3f; const float jumpGroundingPreventionTime = 0.2f; // delay so player doesn't get snapped to ground while jumping const float groundCheckDistanceInAir = 0.07f; // How close we have to get to ground to start checking for grounded again + Vector3 raycastOffset; + Vector3 lastPos; Ray groundRay; // ground ray Ray angleRayLeft; Ray angleRayRight; Ray angleRayForward; Ray angleRayBackwards; + Ray angleRayLeftR; + Ray angleRayRightL; + Ray angleRayForwardB; + Ray angleRayBackwardsF; RaycastHit groundHit; // ground raycast + //Wallrun float wallMaxDistance = 3f; // distance to wall that player can attach from float minimumHeight = .1f; // minimum height player has to be @@ -139,6 +146,7 @@ public class AerialStateManager : NetworkBehaviour //Grapple Variables hookPoints = GameObject.FindGameObjectsWithTag("HookPoint"); //// + lastPos = transform.position; } void Update(){ @@ -256,20 +264,38 @@ public class AerialStateManager : NetworkBehaviour //Checks if player is grounded void GroundCheck(){ + raycastOffset = transform.position - lastPos; + lastPos = transform.position; // Make sure that the ground check distance while already in air is very small, to prevent suddenly snapping to ground float chosenGroundCheckDistance = isGrounded ? (moveController.skinWidth + groundCheckDistance) : groundCheckDistanceInAir; // reset values before the ground check isGrounded = false; - groundRay = new Ray(moveController.transform.position, Vector3.down); - angleRayLeft = new Ray(moveController.transform.position, Quaternion.AngleAxis(45, Vector3.forward) * Vector3.left); - angleRayRight = new Ray(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.forward) * -Vector3.left); - angleRayForward = new Ray(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.left) * Vector3.forward); - angleRayBackwards = new Ray(moveController.transform.position, Quaternion.AngleAxis(45, Vector3.left) * Vector3.forward); + groundRay = new Ray(moveController.transform.position + raycastOffset, Vector3.down); + + angleRayLeft = new Ray(moveController.transform.position + raycastOffset , Quaternion.AngleAxis(45, Vector3.forward) * Vector3.left); + angleRayRight = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.forward) * -Vector3.left); + angleRayForward = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.left) * Vector3.forward); + angleRayBackwards = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(45, Vector3.left) * -Vector3.forward); + + angleRayLeftR = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(45, Vector3.forward) * Vector3.left)); + angleRayRightL = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(-45, -Vector3.forward) * -Vector3.left)); + angleRayForwardB = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(-45, Vector3.left) * Vector3.forward)); + angleRayBackwardsF = new Ray(moveController.transform.position + raycastOffset, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(45, -Vector3.left) * Vector3.forward)); + + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(45, Vector3.forward) * Vector3.left) * 1000,Color.yellow); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(-45, Vector3.forward) * -Vector3.left) * 1000,Color.blue); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(-45, Vector3.left) * Vector3.forward) * 1000,Color.red); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(45, Vector3.left) * -Vector3.forward) * 1000,Color.white); + + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(45, Vector3.forward) * Vector3.left * 1000,Color.yellow); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.forward) * -Vector3.left * 1000,Color.blue); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.left) * Vector3.forward * 1000,Color.red); + // Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(45, Vector3.left) * -Vector3.forward * 1000,Color.white); + //Debug.DrawRay(moveController.transform.position, Quaternion.AngleAxis(-45, Vector3.up) * (Quaternion.AngleAxis(45, Vector3.left) * Vector3.forward) * 1000,Color.white); if (Physics.Raycast(groundRay, out groundHit, moveController.height + groundCheckDistance) && !jumpPressed) { - //Debug.Log(Vector3.Dot(groundHit.normal, transform.up)); // Only consider this a valid ground hit if the ground normal goes in the same direction as the character up if (Vector3.Dot(groundHit.normal, transform.up) > .8f) @@ -282,34 +308,61 @@ public class AerialStateManager : NetworkBehaviour } } } - else if(Physics.Raycast(groundRay, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ - if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ - moveController.Move(groundHit.normal * 20 * Time.deltaTime); - mSM.CancelMomentum(); + else if(currentState != WallRunState){ + if(Physics.Raycast(groundRay, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } } - } - else if(Physics.Raycast(angleRayLeft, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ - if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ - moveController.Move(groundHit.normal * 20 * Time.deltaTime); - mSM.CancelMomentum(); + else if(Physics.Raycast(angleRayLeft, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + Debug.Log("Left"); + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } } - } - else if(Physics.Raycast(angleRayRight, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ - if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ - moveController.Move(groundHit.normal * 20 * Time.deltaTime); - mSM.CancelMomentum(); + else if(Physics.Raycast(angleRayRight, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } } - } - else if(Physics.Raycast(angleRayForward, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ - if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ - moveController.Move(groundHit.normal * 20 * Time.deltaTime); - mSM.CancelMomentum(); + else if(Physics.Raycast(angleRayForward, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } } - } - else if(Physics.Raycast(angleRayBackwards, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ - if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ - moveController.Move(groundHit.normal * 20 * Time.deltaTime); - mSM.CancelMomentum(); + else if(Physics.Raycast(angleRayBackwards, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } + } + else if(Physics.Raycast(angleRayLeftR, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } + } + else if(Physics.Raycast(angleRayRightL, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } + } + else if(Physics.Raycast(angleRayForwardB, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } + } + else if(Physics.Raycast(angleRayBackwardsF, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed && curCoyJumpTimer <= 0){ + if(Vector3.Dot(groundHit.normal, transform.up) <= .8f){ + moveController.Move(groundHit.normal * 20 * Time.deltaTime); + mSM.CancelMomentum(); + } } } }