Added jump and tweaked jump while walking interaction
This commit is contained in:
parent
0e32c69f2a
commit
f58dd0ae5b
@ -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<Vector2>();
|
||||
rawInputMovement = new Vector3(rawInputMovement.x, jumpPower, rawInputMovement.z);
|
||||
rb.velocity = new Vector3(0, jumpPower, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user