How to change first person controller input when passing through a collider?

Hello, amateur Unity user here! I’m using multiple cameras on my scene and a first person controller without its own camera. So the game is basically 3rd person. The cameras alternate when the player passes through various colliders I’ve set up, but the movement is inverted in some cases, because of different camera angles, making it hard for me to control the player.

Is there a way to change the input when the player passes through a collider and the view angle changes? Like, instead of W = forward on the plane no matter which camera is used, I’d like to change it to (when the player passes through collider) W = left on the plane, but seemingly forward because of a different camera angle. And back to the previous input if the player passes through the same collider, of course.

If there are any tutorials on the matter or any scripts, I’d love to know about them. Thanks a lot!

You’ll need a very different solution depending on whether you’re using physics, this answer assumes you aren’t :slight_smile:

I guess you’ll have something similar to this:

if (Input.GetKey(KeyCode.W))
{
    // move the player along it's forward axis
    transform.position += transform.forward * speed * Time.deltaTime;
}

in your character control code. You can change this to use a direction relative to the camera’s forward axis like so:

if (Input.GetKey(KeyCode.W))
{
    // get the raw camera forward axis (using main camera in this example)
    Vector3 forwardDir = Camera.main.transform.forward;
            
    // project onto the xz plane
    forwardDir.y = 0.0f;

    // normalize
    forwardDir.Normalize();

    // move the player along the projected axis
    transform.position += forwardDir * speed * Time.deltaTime;
}

This is assuming you want to keep your player on a flat horizontal plane, but the principle should be roughly the same in a lot of cases. You shouldn’t have to change the way the characters controls when the camera moves, you can always make movement relative.