fixed gravity + jumping

This commit is contained in:
2025-11-21 00:04:37 -08:00
parent bc5cf80f30
commit a98e003edc
6 changed files with 47 additions and 44 deletions

View File

@@ -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()
{