My code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))] public class PlayerController : MonoBehaviour {
public Rigidbody Player;
public Camera Camera;
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void OnCollisionStay(){
isGrounded = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("d"))
{
Player.AddRelativeForce(4, 0, 0);
}
if (Input.GetKey("a"))
{
Player.AddRelativeForce(-4, 0, 0);
}
if (Input.GetKey("w"))
{
Player.AddRelativeForce(0, 0, 4);
}
if (Input.GetKey("s"))
{
Player.AddRelativeForce(0, 0, -4);
}
if (Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
} } }