diff --git a/Assets/Scripts/CharacterMovement.cs b/Assets/Scripts/CharacterMovement.cs index 83933c3..248fd08 100644 --- a/Assets/Scripts/CharacterMovement.cs +++ b/Assets/Scripts/CharacterMovement.cs @@ -17,21 +17,30 @@ public class CharacterMovement : MonoBehaviour [Header("Character properties")] public bool isGrounded; + public bool isJumping; private Vector3 rawInputMovement; private void FixedUpdate() { - Debug.Log(isGrounded); if (canWalk || canJump) { - rb.AddForce(new Vector3(rawInputMovement.x * movementSpeed, rawInputMovement.y, rawInputMovement.z * movementSpeed), ForceMode.Impulse); + if (isGrounded) + { + //The walk is actually handled here + rb.AddForce(rawInputMovement * movementSpeed, ForceMode.Impulse); + } } + Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * 1, Color.yellow); RaycastHit hit; - if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 1.5f)) + if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 1f, LayerMask.GetMask("Floor")) || + Physics.Raycast(transform.position, transform.TransformDirection(Vector3.up), out hit, 1f, LayerMask.GetMask("Floor")) || + Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 1f, LayerMask.GetMask("Floor")) || + Physics.Raycast(transform.position, transform.TransformDirection(Vector3.back), out hit, 1f, LayerMask.GetMask("Floor")) || + Physics.Raycast(transform.position, transform.TransformDirection(Vector3.left), out hit, 1f, LayerMask.GetMask("Floor")) || + Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out hit, 1f, LayerMask.GetMask("Floor"))) { - Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * hit.distance, Color.yellow); isGrounded = true; } else @@ -52,10 +61,10 @@ public class CharacterMovement : MonoBehaviour public void Jump(InputAction.CallbackContext value) { - if (canJump && isGrounded) + if(canJump && isGrounded) { - Vector2 inputMovement = value.ReadValue(); - rawInputMovement = new Vector3(rawInputMovement.x, jumpPower, rawInputMovement.z); + rb.velocity = new Vector3(0, jumpPower, 0); } + } }