This commit is contained in:
2025-11-20 19:54:40 -08:00
parent 80be13ce72
commit bc5cf80f30
2 changed files with 34 additions and 19 deletions

Binary file not shown.

View File

@@ -77,6 +77,15 @@ public class PlayerMovement : MonoBehaviour
public GameObject uiController;
public PlayerInput playerInput;
InputAction jumpAction;
private void Awake()
{
jumpAction = playerInput.actions["Jump"];
}
void Start()
{
cinemachineCam = GameObject.Find("CinemachineCamera");
@@ -86,6 +95,7 @@ public class PlayerMovement : MonoBehaviour
void Update()
{
timeSinceLastSwing += Time.deltaTime;
if (timeSinceLastSwing > .5f)
lastSwing = 0;
@@ -190,16 +200,21 @@ public class PlayerMovement : MonoBehaviour
// controller.Move(move2 * Time.deltaTime);
//}
controller.Move(velocity * Time.deltaTime);
if (!controller.isGrounded)
if (!controller.isGrounded && !jumpAction.WasPerformedThisFrame())
{
velocity.y += gravity * Time.deltaTime;
}
else if (controller.isGrounded)
else if (controller.isGrounded && !jumpAction.WasPerformedThisFrame())
{
//velocity.y = 0;
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)
{
@@ -275,18 +290,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()
{