using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
[Header("References")]
public Rigidbody rb;
public Transform head;
public Camera camera;
[Header("Configurations")]
public float walkSpeed;
public float runSpeed;
public float jumpSpeed;
[Header("Runtime")]
Vector3 newVelocity;
bool isGrounded = false;
bool isJumping = false;
// Start is called before the first frame update
void Start() {
//Cursor Locked For Rotation
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update() {
//Horizontal Rotation
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * 2f);
newVelocity = Vector3.up * rb.velocity.y;
float speed = Input.GetKey(KeyCode.LeftShift) ? runSpeed : walkSpeed;
newVelocity.x = Input.GetAxis("Horizontal") * speed;
newVelocity.z = Input.GetAxis("Vertical") * speed;
if (isGrounded) {
if (Input.GetKeyDown(KeyCode.Space) && !isJumping) {
newVelocity.y = jumpSpeed;
isJumping = true;
}
}
}
void FixedUpdate() {
rb.velocity = transform.TransformDirection(newVelocity);
}
void LateUpdate() {
//Vertical Rotation
Vector3 e = head.eulerAngles;
e.x -= Input.GetAxis("Mouse Y") * 2f;
e.x = RestrictAngle(e.x, -85f, 85f);
head.eulerAngles = e;
}
public static float RestrictAngle(float angle, float angleMin, float angleMax) {
if (angle > 180)
angle -= 360;
else if (angle < -180)
angle += 360;
if (angle > angleMax)
angle = angleMax;
if (angle < angleMin)
angle = angleMin;
return angle;
}
void OnCollisionStay(Collision col) {
isGrounded = true;
isJumping = false;
}
void OnCollisionExit(Collision col) {
isGrounded = false;
}
}```
What does “jump is inconsistant” mean? Does that mean the character doesn’t always jump when you press the button, or is there some aspect of the jump that’s inconsistant?