Hi guys. I’m pretty new to Unity and i started to follow some different tutorials to end up
with a movement script for my ball and a jump script
I just can’t seem to make the jump script work? What am i doing wrong?
Here is a picture of the problem
using System.Collections;
public class Movement : MonoBehaviour {
public float JumpHeight;
public float speed;
private Rigidbody rb;
private float isFalling = false;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
GetComponent.<Rigidbody>().velocity.y = JumpHeight;
isFalling = true;
}
}
function OnCollisionStay ()
{
isFalling = false;
}
}