I am trying to implement camera movement like it is done in Guild Wars 2. Scenario is when A and D keys are pressed, the player rotates right / left and the camera follows and stays behind the character / player like this
(Starts at 23 seconds)
https://www.youtube.com/watch?v=XkHJ2uSrLjE
I can get the basic working fine, and I did it 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);
}
}
Now the next part I am trying to achieve , 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)
https://www.youtube.com/watch?v=qTTDaeuHl80
so at present moment with my current code
https://www.youtube.com/watch?v=a53lZ_0BDtg
camera and player 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?