using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public float sprintSpeed;
public float gravity = 9.9f;
public float jumpheight = 5.0f;
private PlayerControls controls;
private Vector2 moveInput;
private Vector3 jumpInput;
public Transform groundCheck;
public float groundDistance = 0.15f;
public LayerMask groundMask;
Vector3 velocity;
private Rigidbody rb;
private bool isGrounded;
private void Awake()
{
controls = new PlayerControls();
rb = GetComponent
controls.Player.Move.performed += ctx => {
moveInput = ctx.ReadValue
};
controls.Player.Move.canceled += ctx => {
moveInput = Vector2.zero;
};
controls.Player.Jump.performed += ctx => {
if (isGrounded)
{
velocity.y = Mathf.Sqrt(jumpheight * 2f * gravity); // <-- use this in FixedUpdate
}
};
}
private void OnEnable()
{
controls.Enable();
controls.Player.Enable(); // ensures the action map is active
}
private void OnDisable()
{
controls.Disable();
}
private void OnDrawGizmosSelected()
{
if (groundCheck == null) return;
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(groundCheck.position, groundDistance);
}
>1/2 of my movement code