I want to make my character only jump when touching the ground. My code isn’t really good, and its really simple. Please help. This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
private bool onGround = true;
public Rigidbody rb;
public float ForwardForce = 1000f;
public float SidewaysForce = 500f;
public float Jump = 1000f;
// Update is called once per frame
void Update () {
if(Input.GetKey("w"))
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
}
if(Input.GetKey("d"))
{
rb.AddForce(SidewaysForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("a"))
{
rb.AddForce(-SidewaysForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("s"))
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
}
if(Input.GetKey("space"))
{
rb.AddForce(0, Jump * Time.deltaTime, 0);
}
}
}