I am trying to make a first person controller for my game. It works, but it is extremely uncomfortable to use and it is extremely jittery. Can someone help me find an alternative that is simple, fulfills the same purpose, and solves the previously mentioned problems?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour {
public GameObject controlsHelpText;
public GameObject Player;
public GameObject Camera;
public Rigidbody PlayerRB;
public float speed = 1;
public float sensitivity = 1;
private void Start ()
{
Cursor.lockState = CursorLockMode.Locked;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "PowerUp")
{
speed += 0.2f;
}
}
void FixedUpdate()
{
if (Input.GetKey("w"))
{
Player.transform.Translate(0, 0, speed);
}
if (Input.GetKey("s"))
{
Player.transform.Translate(0, 0, -speed / 2);
}
if (Input.GetKey("d"))
{
Player.transform.Translate(speed / 2, 0, 0);
}
if (Input.GetKey("a"))
{
Player.transform.Translate(-speed / 2, 0, 0);
}
if (Input.anyKeyDown)
{
controlsHelpText.SetActive(false);
}
}
void Update()
{
if (Input.GetAxis("Mouse X") > 1)
{
Player.transform.Rotate(0, sensitivity, 0);
}
if (Input.GetAxis("Mouse X") < -1)
{
Player.transform.Rotate(0, -sensitivity, 0);
}
if (Input.GetAxis("Mouse Y") > 1)
{
Camera.transform.Rotate(-sensitivity, 0, 0);
}
if (Input.GetAxis("Mouse Y") < -1)
{
Camera.transform.Rotate(sensitivity, 0, 0);
}
}
}