Here is my code:
[RequireComponent(typeof(Rigidbody))]
public class PlayerMovement : MonoBehaviour
{
public float _speed;
public float jumpForce;
private bool isGrounded;
public Vector3 jump;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
private void OnCollisionStay(Collision collision)
{
isGrounded = true;
}
private void OnCollisionExit(Collision collision)
{
isGrounded = false;
}
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
transform.Translate(new Vector3(horizontalInput, 0, verticalInput) * _speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse );
}
}
}
Note: The higher the jump is, the bigger the lag/stuttering gets
I’m a total beginner and i’ve been trying to figure this out for the last 3 hours but I just can’t find the problem.
I thought it was because of the camera and tried to build the game but it lags anyways