Hi, I’m making a simple 3D platformer and I’m pretty much done I just can’t figure out how to make my character jump only when he is touching the ground/platforms. Right now I can spam jump and he’ll keep jumping. Here’s my code. I was wondering if anyone could help, thanks.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float movementSpeed;
public float jumpSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
Vector3 forward = Input.GetAxis ("Vertical") * Vector3.up * movementSpeed; // * transform.TransformDirection;
Vector3 rotate = Input.GetAxis("Horizontal")* movementSpeed * Vector3.left;
rigidbody.AddRelativeForce (forward);
rigidbody.AddRelativeForce(rotate);
//Debug.Log(Input.GetAxisRaw("Horizontal"));
if(Input.GetButtonDown("Jump"))
{
rigidbody.AddRelativeForce(Vector3.forward * jumpSpeed, ForceMode.Impulse);
}
}
}