fixed gravity + jumping
This commit is contained in:
@@ -187,6 +187,26 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
|
||||
|
||||
|
||||
if (controller.isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -0.5f;
|
||||
|
||||
}
|
||||
//else if (controller.isGrounded && !jumpAction.WasPerformedThisFrame())
|
||||
//{
|
||||
// velocity.y = 0;
|
||||
//}
|
||||
if (jumpAction.WasPerformedThisFrame() && controller.isGrounded)
|
||||
{
|
||||
//Debug.Log("jumped");
|
||||
//velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity);
|
||||
}
|
||||
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
|
||||
Debug.Log(controller.isGrounded);
|
||||
|
||||
if (canWalk /*&& !running*/)
|
||||
{
|
||||
Vector3 move = new Vector3(moveInput.x * speed, 0, moveInput.y * speed);
|
||||
@@ -200,21 +220,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
// controller.Move(move2 * Time.deltaTime);
|
||||
//}
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
if (!controller.isGrounded && !jumpAction.WasPerformedThisFrame())
|
||||
{
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
}
|
||||
else if (controller.isGrounded && !jumpAction.WasPerformedThisFrame())
|
||||
{
|
||||
velocity.y = 0;
|
||||
}
|
||||
else if (jumpAction.WasPerformedThisFrame() && controller.isGrounded)
|
||||
{
|
||||
Debug.Log("jumped");
|
||||
velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity);
|
||||
}
|
||||
|
||||
Debug.Log(controller.isGrounded);
|
||||
}
|
||||
public void PauseGame(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -290,18 +295,18 @@ public class PlayerMovement : MonoBehaviour
|
||||
dashDistanceTimer = 0;
|
||||
}
|
||||
}
|
||||
//public void OnJump(InputAction.CallbackContext context)
|
||||
//{
|
||||
// if (context.performed && controller.isGrounded)
|
||||
// {
|
||||
// velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity);
|
||||
// jumped = true;
|
||||
// }
|
||||
// if (context.canceled && !controller.isGrounded)
|
||||
// {
|
||||
// jumped = false;
|
||||
// }
|
||||
//}
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed && controller.isGrounded)
|
||||
{
|
||||
velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity);
|
||||
jumped = true;
|
||||
}
|
||||
if (context.canceled && !controller.isGrounded)
|
||||
{
|
||||
jumped = false;
|
||||
}
|
||||
}
|
||||
private void MyInput()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user