Movement help

My camera is controlled with my mouse and my player’s forward is the camera’s forward, which means that when i look up and press W, my player goes flying up (im a beginner, so sorry if there was a simple answer)

Movement script

public class Jump : MonoBehaviour
{
    public float jumpForce = 30000f;
    public Rigidbody rb;
    public float sidewaysForce = 6000f;
    private bool isGrounded = false;
    public float FowardForce = 2000f;
    public float lookSensitivity = 3;
    public Transform camera;




    void FixedUpdate()
    {

        rb.rotation = camera.rotation;

        transform.forward = camera.forward;

        if (Input.GetKey(KeyCode.D))
        {
            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
        }
        if (Input.GetKey(KeyCode.A))
        {
            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
        }
        if (Input.GetKey(KeyCode.S))
        {
            rb.AddForce(0, 0, -FowardForce * Time.deltaTime); ;
        }
        if (Input.GetKey(KeyCode.W))
        {
            rb.AddForce(FowardForce * transform.forward);
        }
        if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(0, jumpForce * Time.deltaTime, 0);
            jumpForce = 0f;

and the camera script

public class Follow : MonoBehaviour {
public Transform player;

public float mouseSensitivity = 100.0f;
public float clampAngle = 80.0f;
// Update is called once per frame
private float rotY = 0.0f; // rotation around the up/y axis
private float rotX = 0.0f; // rotation around the right/x axis

void Start()
{
    Vector3 rot = transform.localRotation.eulerAngles;
    rotY = rot.y;
    rotX = rot.x;
}

void Update()
{
    float mouseX = Input.GetAxis("Mouse X");
    float mouseY = -Input.GetAxis("Mouse Y");

    rotY += mouseX * mouseSensitivity * Time.deltaTime;
    rotX += mouseY * mouseSensitivity * Time.deltaTime;

    rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);

    Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
    transform.rotation = localRotation;

    transform.position = player.position;

}

}

So have x and y separated and have the movement direction attached to only one?

this is untested but here would be the idea:

    	GameObject head;
    	void Start () {
    
    		head = new GameObject ();
    		head.transform.parent = gameObject.transform;
    		head.transform.localRotation = Quaternion.identity;
    		head.transform.localPosition = Vector3.zero;
    		Camera.main.transform.parent = head.transform;
    		Camera.main.transform.localRotation = Quaternion.identity;
    		Camera.main.transform.localPosition = Vector3.zero;
    	}
    	
    
    	void Update () {
    		float speed = 50;
    		float y = 0;
    		float x = 0;
               //buttons only move base character
    		if (Input.GetKey(KeyCode.S)){y=1;}
    		if (Input.GetKey(KeyCode.W)){y=-1;}
    		if (Input.GetKey(KeyCode.A)){x=-1;}
    		if (Input.GetKey(KeyCode.D)){x=1;}
    		y = y *speed* Time.deltaTime;
    		x = x* speed* Time.deltaTime;
            gameObject.rigidbody.AddForce(transform.right*x);
    		gameObject.rigidbody.AddForce(transform.forward*y);

               // mouse x spins base
    		float mouseX = Input.GetAxis ("Mouse X") * Time.deltaTime*speed;
               // mouse y tilts head
    		float mouseY = -Input.GetAxis("Mouse Y")*Time.deltaTime*speed;
            transform.Rotate(new Vector3(0,mouseX,0));
    		head.transform.Rotate(new Vector3(mouseY,0,0));
    	    
    	}

basically you create a invisable “head” object that tilts up and down with the camera attached. then it automatically rotates left and right with the character when it is parented.

this gives you independent movement of where the body is moving and where the head and camera are looking