Hello, I’m having some trouble with getting proper first-person character controls. I’ve found some resources on here that bettered the problem but nothing that completely fixed it. Whenever I first press an arrow key, my character seems to jump a little but moves mostly fine. Some occasional jumps while moving. I’m not sure what to change, I’m using the Character Controller
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
private CharacterController controller;
private float verticalVelocity;
private float gravity = 14.0f;
private float jumpForce = 10.0f;
private void Start()
{
controller = GetComponent<CharacterController>();
}
private void FixedUpdate()
{
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
Vector3 moveVector = Vector3.zero;
moveVector.x = Input.GetAxis("Vertical") * 5.0f;
moveVector.y = verticalVelocity;
moveVector.z = Input.GetAxis("Horizontal") * -5.0f;
controller.Move(moveVector * Time.deltaTime);
}
}