So I’ve been tweaking with some code to make a third person controller with a stationary camera (and the controller goes in the direction of the camera, I’m gonna get it to move later). And saying it’s broken is an understatement. I attached the script to a capsule and then I attached the camera in the component inspector so that the direction the camera is facing resets the movement controls. However, when I start the game, it freezes. In the one time I got it to work, the controls were very shakey (like if I pressed two buttons at once it would shake) or they didn’t all have the same speed (the w button was faster than the s button). Can someone help me? I’ve been working on this for a while.
Here is the script. It was originally one I got from the web but I had to tweak it.
using UnityEngine;
public class Movement_Script : MonoBehaviour
{
public float movementSpeed = 7.0F;
public float gravityForce = 100.0F;
public Transform cameraMovement ;
private Vector3 movement = Vector3.zero;
void FixedUpdate() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
movement = cameraMovement.TransformDirection(movement);
if (Input.GetKeyDown(KeyCode.LeftShift))
{
movementSpeed = 9.0f;
}
movement.y -= gravityForce * Time.deltaTime;
controller.Move(movement * Time.deltaTime);
}
}
}