Question by
$$anonymous$$ · Oct 23, 2015 at 03:27 PM ·
3d
Help with jump script
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;
}
}
untitled.jpg
(292.3 kB)
untitled2.jpg
(21.4 kB)
Comment
On line 28 there's a '.' too much, is this just a copy paste mistake? it should be:
GetComponent<Rigidbody>().velocity.y=JumpHeight;
ins$$anonymous$$d of: GetComponent.<Rigidbody>().velocity.y=JumpHeight;
Answer by springwater · Oct 23, 2015 at 04:40 PM
well, it looks like as soon as it starts to jump.. you tell it, .. its falling.. and in turn its not allowed to be jumping^^