- Home /
Question by
notjoeytribbiani · May 15, 2019 at 09:02 AM ·
scripting problemjumpjumping object
Im doing a 3d endless runner, but i just cant get my cube(player) to jump when i press the spacebar, ive searced everywhere and tried a lot of different jump scripts but to no avail.
using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class Jump : MonoBehaviour { public float jumpHeight = 7f; public bool isGrounded;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector3.up * jumpHeight);
}
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Ground")
{
isGrounded = true;
}
}
void OnCollisionExit(Collision other)
{
if (other.gameObject.tag == "Ground")
{
isGrounded = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
I need help with fixing my "up special" mechanic. 1 Answer
Help with jump cooldown 2 Answers
Make a Jump Delay 1 Answer
Player jump not working correctly 1 Answer
I cant make my character jump 1 Answer