Rigidbody First Person Controller Movement
Hey guys! I am hoping that someone can guide me through this issue I have been having for the past 2 weeks or so. I am trying to make a plain old rigidbody first person controller in Unity 5.4.1. I can't seem to figure out how to make my player move correctly. I need the player to move almost instantly but with half a second or so of acceleration and deceleration. I would not like to use axis inputs but rather individual buttons. Keep in mind that I do NOT have a standard CharacterController component on my player. I will post a screenie of my editor window. Here is my code so far (minus the movement):
using UnityEngine;
using System.Collections;
public class CharacterController : MonoBehaviour {
public Rigidbody rb;
// axis input vars
public float walkSpeed = 5.0f;
public float walkAcceleration = 0.1f;
float forwardSpeed = 0.0f;
float backSpeed = 0.0f;
float rightSpeed = 0.0f;
float leftSpeed = 0.0f;
// sprint vars
public float sprintSpeed = 10.0f;
// mouse input vars
public float mouseSensitivity = 5.0f;
public float upDownRange = 80.0f;
float verticalRotation = 0;
// use this for initialization
void Start () {
Screen.lockCursor = true;
rb = GetComponent<Rigidbody>();
}
void Update () {
if (Input.GetKeyDown("escape"))
Screen.lockCursor = false;
// sprint
if (Input.GetButtonDown("Sprint")) {
forwardSpeed = sprintSpeed;
}
if (Input.GetButtonUp("Sprint")) {
forwardSpeed = walkSpeed;
}
}
void FixedUpdate () {
// mouse inputs
float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
}
}
Any help is MUCH appreciated as I have tried just about everything google has to offer and would eventually like to release this as a game. Thank you!