using UnityEngine;
using System.Collections;
public class Moves : MonoBehaviour {
public float speed = 2f;
public float jumpHeight = 300f;
public float movementAmount = 0.001f;
public Rigidbody rb;
public bool isGrounded;
public LayerMask whatIsGround;
public Transform groundCheck;
public float distToGround;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
// Check for space presses in the update loop!
void Update()
{
isGrounded = Physics.Raycast (transform.position, -Vector3.up, distToGround + 0.1f);
float h = Input.GetAxis ("Horizontal");
rb.velocity = new Vector3 (h * speed, rb.velocity.y, rb.velocity.z);
float v = Input.GetAxis ("Vertical");
rb.velocity = new Vector3 (rb.velocity.x, rb.velocity.y, v * speed);
if (Input.GetKey ("space") && isGrounded) {
rb.AddForce (0, jumpHeight, 0);
}
}
}
I’m pressing space, but my cube isn’t jumping at all. Are there any errors I don’t know about?