Player moving in the direction of the camera

Hi there!

I am very new to unity and I’m trying to create a third person game. my character can move normally but I don’t know how to make it so you move in the direction that the camera is facing.

This is my character controller:

public class ThirdPersonMovement2 : MonoBehaviour
{
    public Rigidbody rb;

    public float ForwardForce = 100f;
    public float SidewaysForce = 100f;
    public float BackwardsForce = 100f;

    void Update()
    {

        if (Input.GetKey("w"))
        {
            rb.AddForce (0, 0, ForwardForce);
        }

        if (Input.GetKey("a"))
        {
            rb.AddForce (-SidewaysForce, 0, 0);
        }

        if (Input.GetKey("d"))
        {
            rb.AddForce (SidewaysForce, 0, 0);
        }

        if (Input.GetKey("s"))
        {
            rb.AddForce (0, 0, -ForwardForce);
        }

    }
}

the player itself is a parent object that has a rigidbody, a capsule collider and the script, with a child object that has all of the graphics of the player.

please help me because I have no idea how to make the character move in the direction of the camera and I would really like to make this work.

You mean the camera that follow the player and not the vice-versa right?
If that’s right this is a good tutorial where you can also make cool stuff while the player is aiming:

But if you need something for beginner you can find lot of tutorials into Unity Learn website

Ps. Have you ever tried the new Input System to create player’s input instead of writing the code manually? It’s really good to start a prototype or to learn and if you need to implement something with the code you can always do it, just to keep everything cleaner. Check it out :wink:

no, my camera is good but whenever i change where to camera is facing the player still moves in the same direction. i want the player to move in the direction that the camera is facing but i don’t know how to do that.