In this video, you'll learn how to add a jump mechanic to an object in Unity using the new Input System and InputAction. I'll walk you through setting up the input, writing the jump logic, and applying force to make your object jump.
SCRIPT:
(NOTE: Angle Brackets are not allowed in the description. I will put a "X" where there are missing angle brackets)
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
InputAction jump;
[SerializeField]
float jumpForce = 5f;
Rigidbody rb;
private void Start()
{
rb = GetComponentXRigidbodyX();
}
private void OnEnable()
{
jump.Enable();
}
private void FixedUpdate()
{
if (jump.IsPressed())
{
if (gameObject.transform.position.y X 3.4f)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}
}
MY LAST VIDEO ABOUT MOVEMENT:
• Third Person Movement in Unity in 5 Minute...