|
|
|
|
|
|
[NonSerialized] public bool attackInput; |
|
|
|
[NonSerialized] public Vector3 movementInput; //Initial input coming from the Protagonist script
|
|
|
|
[NonSerialized] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
|
|
|
|
//[NonSerialized] public ControllerColliderHit lastHit;
|
|
|
|
[NonSerialized] public Vector3 rayGroundNormal = Vector3.up; |
|
|
|
[NonSerialized] public ControllerColliderHit lastHit; |
|
|
|
[NonSerialized] public Vector3 stepNormal = Vector3.up; |
|
|
|
[NonSerialized] public Vector3 spherecastGroundNormal = Vector3.up; |
|
|
|
[NonSerialized] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
|
|
|
|
|
|
|
|
|
|
|
public const float AIR_RESISTANCE = 5f; |
|
|
|
|
|
|
|
public Transform ray1, ray2, ray3; //Temporary references
|
|
|
|
public bool canMoveForward; |
|
|
|
//private void OnControllerColliderHit(ControllerColliderHit hit)
|
|
|
|
//{
|
|
|
|
// lastHit = hit;
|
|
|
|
//}
|
|
|
|
private void OnControllerColliderHit(ControllerColliderHit hit) |
|
|
|
{ |
|
|
|
lastHit = hit; |
|
|
|
} |
|
|
|
|
|
|
|
//Adds listeners for events being triggered in the InputReader script
|
|
|
|
private void OnEnable() |
|
|
|
|
|
|
|
|
|
|
private void GroundCheck() |
|
|
|
{ |
|
|
|
rayGroundNormal = Vector3.zero; |
|
|
|
if(Physics.Raycast(ray1.position, Vector3.down, out RaycastHit hitResults, 1f)) |
|
|
|
{ |
|
|
|
rayGroundNormal += hitResults.normal; |
|
|
|
} |
|
|
|
if (Physics.Raycast(ray2.position, Vector3.down, out hitResults, 1f)) |
|
|
|
{ |
|
|
|
rayGroundNormal += hitResults.normal; |
|
|
|
} |
|
|
|
if (Physics.Raycast(ray3.position, Vector3.down, out hitResults, 1f)) |
|
|
|
{ |
|
|
|
rayGroundNormal += hitResults.normal; |
|
|
|
} |
|
|
|
|
|
|
|
rayGroundNormal.Normalize(); |
|
|
|
|
|
|
|
//Ray sphereRay = new Ray(transform.position + Vector3.up * .3f, Vector3.down);
|
|
|
|
//if (Physics.SphereCast(sphereRay, .3f, out hitResults, 1f))
|
|
|
|
//{
|
|
|
|
// spherecastGroundNormal = hitResults.normal;
|
|
|
|
|
|
|
|
// if(!rayFoundGround)
|
|
|
|
// {
|
|
|
|
// rayGroundNormal = spherecastGroundNormal;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// spherecastGroundNormal = Vector3.up;
|
|
|
|
//}
|
|
|
|
|
|
|
|
Vector3 origin = transform.position + Vector3.up * 1.5f; |
|
|
|
Debug.DrawLine(origin, origin + rayGroundNormal, Color.red); |
|
|
|
//Debug.DrawLine(origin, origin + spherecastGroundNormal, Color.green);
|
|
|
|
canMoveForward = !Physics.Raycast(ray1.position, transform.forward, out RaycastHit hitResults, .2f); |
|
|
|
} |
|
|
|
|
|
|
|
private void RecalculateMovement() |
|
|
|