Hello , I am having some hard time with programming , basiclly I am making pre jump to work , I pull my gamepad right stick down = player plays prejump animation and when I release it it jumps in the air , the problem is I just cant get isGrounded function to work with my code , I tried multiple ways to do it but It just wouldn’t work , if anyone here has time to help would be nice , I also marked where the jump code is in the script with //
using UnityEngine.InputSystem;
public class JumpController : MonoBehaviour
{
PlayerControlls controls;
public Vector3 jump;
public float jumpForce = 100f;
Rigidbody rb;
public GameObject PreJumpObject;
public bool isGrounded;
void OnCollisionStay()
{
isGrounded = true;
}
void OnCollisionExit()
{
isGrounded = true;
}
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 60f, 0.0f);
}
void Awake()
{
controls = new PlayerControlls();
controls.Gameplay.PreJump.performed += ctx => PreJump();
controls.Gameplay.PreJump.canceled += ctx => PreJumpEndFunction();
}
void PreJumpEndFunction()
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse); //this is the jump code , where I cant figure out how to do isGrounded
}
void PreJump()
{
PreJumpObject.GetComponent<Animator>().Play("PreJumpLooks");
}
void OnEnable()
{
controls.Gameplay.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
}
}