added small jump
This commit is contained in:
parent
6d0a7912e0
commit
0e32c69f2a
@ -415,7 +415,8 @@ MonoBehaviour:
|
||||
canWalk: 1
|
||||
canJump: 1
|
||||
movementSpeed: 1.5
|
||||
jumpPower: 5
|
||||
jumpPower: 10
|
||||
isGrounded: 0
|
||||
--- !u!1 &684542796
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -16,17 +16,29 @@ public class CharacterMovement : MonoBehaviour
|
||||
[SerializeField] private float jumpPower;
|
||||
|
||||
[Header("Character properties")]
|
||||
public bool isGrounded;
|
||||
|
||||
|
||||
private Vector2 rawInputMovement;
|
||||
private Vector3 rawInputMovement;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Debug.Log(isGrounded);
|
||||
if (canWalk || canJump)
|
||||
{
|
||||
rb.AddForce(rawInputMovement * movementSpeed, ForceMode.Impulse);
|
||||
rb.AddForce(new Vector3(rawInputMovement.x * movementSpeed, rawInputMovement.y, rawInputMovement.z * movementSpeed), ForceMode.Impulse);
|
||||
}
|
||||
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 1.5f))
|
||||
{
|
||||
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * hit.distance, Color.yellow);
|
||||
isGrounded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawInputMovement = new Vector3(rawInputMovement.x, 0, rawInputMovement.z);
|
||||
isGrounded = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Walk(InputAction.CallbackContext value){
|
||||
@ -40,11 +52,10 @@ public class CharacterMovement : MonoBehaviour
|
||||
|
||||
public void Jump(InputAction.CallbackContext value)
|
||||
{
|
||||
if (canJump)
|
||||
if (canJump && isGrounded)
|
||||
{
|
||||
Vector2 inputMovement = value.ReadValue<Vector2>();
|
||||
rawInputMovement = new Vector3(rawInputMovement.x, jumpPower, rawInputMovement.y);
|
||||
canJump = false;
|
||||
rawInputMovement = new Vector3(rawInputMovement.x, jumpPower, rawInputMovement.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user