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