Camera Movement - Snap Camera back to origin in relation to the player object

I have since gone back to nail down camera movement and third person control. In this case I am trying to implement the camera and character movement that’s implemented in Guild Wars 2.

Detail: When A and D keys are pressed the player rotates right / left and the camera follows and stays behind the character. Example of implementation (start at 23 seconds)

This I was able to achieve in this way

private void KeysRotateCameraAndPlayer()
    {
        float keysOrbitingSpeed = 120;
        this.player = GameObject.FindWithTag("Player").transform;

        if (Input.GetKey(KeyCode.A))
        {
            Debug.Log("Rotate Left");
            CenterPoint.eulerAngles -= new Vector3(0, 360 + Time.deltaTime * keysOrbitingSpeed, 0);
            player.eulerAngles -= new Vector3(0, 360 + Time.deltaTime * keysOrbitingSpeed, 0);

        }
        else if (Input.GetKey(KeyCode.D))
        {
            Debug.Log("Rotate Right");
            CenterPoint.eulerAngles += new Vector3(0, 360 + Time.deltaTime * keysOrbitingSpeed, 0);
            player.eulerAngles += new Vector3(0, 360 + Time.deltaTime * keysOrbitingSpeed, 0);
        }
    }

Detail: Now for the next part, when the camera is rotated / orbited around the player using the mouse and is left in a position that is not the origin i.e behind the player (in relation to player)… when A and D keys are pressed, what happens in GW2 is the camera seems to snap back to the origin and then continue to follow the player from the back ( or its relation origin with regards to the player Object if that makes sense)

This is what the game does (which I hope to achieve)

With the current code shown above, my implementation


will continue to rotate (with A and D), from where the camera was last left during orbit. How can I add to this, to force the camera to snap back to origin like they have in Guild Wars 2?

Privacy & Terms