Can someone give me a little assistance on a scripting issue I've been having?

Hey, Unity users! This should be a very easy fix, but I’m a novice programmer in C# and I don’t know what I can do. I wrote this script to make a third person character controller. The idea is that the controller would move forward in the direction the camera is facing. The camera (which is attached to the script in the inspector) does not move (yet). I really feel like my script should work, however it just doesn’t. When I start up the game, 9/10 times, nothing happens but the game is running. And when it does move, the controls are weird or shakey. Can someone lend me a hand? I would really appreciate it! Here is the script:

public class MovementScript : MonoBehaviour
{
	public float movementSpeed = 6.0F;
	public float levelGravity = 20.0F;

	private Vector3 movementForce = Vector3.zero;
	public Transform cameraMovement;
	public CharacterController characterController;

	void Start()
	{
		characterController = GetComponent<CharacterController>();
	}

	void Update()
	{
		if (characterController.isGrounded)
		{
			if (Input.GetKey(KeyCode.W))
            {
				movementForce = cameraMovement.TransformDirection(movementForce);
			}
			if (Input.GetKey(KeyCode.D))
			{
				movementForce = transform.position += Vector3.right * movementSpeed * Time.deltaTime;
			}
			if (Input.GetKey(KeyCode.A))
			{
				movementForce = transform.position += Vector3.left * movementSpeed * Time.deltaTime;
			}
			if (Input.GetKey(KeyCode.S))
            {
				movementForce = transform.position += Vector3.down * movementSpeed * Time.deltaTime;
            }
		}
		characterController.Move(movementForce * Time.deltaTime);
		movementForce *= movementSpeed;
	}
}

@JustAbhi The camera isn’t supposed to move. It’s not a traditional 3rd person controller. The camera should stay stationary. The code you wrote (thank you) got the thing to move but for some reason, the horizontal movement controls are reversed. So when I press “A” instead of going left, it goes right, and vice versa. If you know how to help with this issue let me know, but otherwise, thank you so much for your help, dude!!! :slight_smile:

I think something like this is what you want

public class MovementScript : MonoBehaviour
 {
     public float movementSpeed = 6.0F;
     public float levelGravity = 20.0F;
 
     private Vector3 movementForce = Vector3.zero;
     public Transform cameraMovement;
     public CharacterController characterController;
 
     void Start()
     {
         characterController = GetComponent<CharacterController>();
     }
 
     void Update()
     {
        //movementForce = Vector3.zero //Dis you forget to reset speed before computing or is it wanted ? It will make things look like you're sliding

         if (characterController.isGrounded)
         {
             if (Input.GetKey(KeyCode.W))
             {
                 movementForce += cameraMovement.forward; //Use camera direction instead of character's
             }
             if (Input.GetKey(KeyCode.D))
             {
                 movementForce = cameraMovement.right
             }
             if (Input.GetKey(KeyCode.A))
             {
                 movementForce -= cameraMovement.right
             }
             if (Input.GetKey(KeyCode.S))
             {
                 movementForce -= cameraMovement.forward
             }
         }
         movementForce *= movementSpeed; //Why multiplying speed here again ? Again maybe that's what you want but looks strange to me
         //I moved it before to apply the speed before movement
         characterController.Move(movementForce * Time.deltaTime); //You already use deltaTime here, no need to use before
     }
 }