Third Person camera movement like Guild Wars 2

Hello folks,
I am trying to achieve the camera movement like in Guild Wars 2. (I just love the UI and movement in that game). I have two videos here one in Guild Wars 2 to show my intended functionality and one in Unity to show how far I am with that functionality.

Guild Wars 2 scene
Guild Wars 2 Camera Movement

Unity scene
Unity RPG Game Camera Movement

Now from the videos,

01 - One can click (and hold) the right mouse button and move the mouse left and right which pans the camera around the player object. In the GW2 scene when the right mouse button is clicked, the cursor is changed to an invisible state and does not move from its current position when you clicked the mouse. While what I currently have in unity is… the camera will pan as intended, but mouse position keeps moving up to the edge of the screen, and with multi-monitors in my case the cursor then moves out of the game screen. Question is how do I keep the mouse cursor in one position, when I click the right mouse button?

02 - On clicking the right mouse button and moving the mouse up and down… in GW2 moving mouse up, rotates the camera up, and moving mouse down rotates the camera down. In my unity scene (screen recorder didn’t capture cursor), its the opposite. moving up, rotates down and vice versa… i.e the up/dpwn movement is inverted by default in unity if not specified?
How can I change this to mimic whats I have in GW2?

03 - pressing the A and D keys rotates/moves the player object while keeping the camera behind the player. What I have in unity at the moment when I press the keys is the player will move left and right instead. Did we bind these keys to player movement when we added keyboard / controller support? My memory is short, will check the previous videos again.
How can I re-purpose these two keys to rotate the player and keep camera behind player at the same time?

This is my current Third Person Camera script

public class CameraThirdPerson : MonoBehaviour {

    private const float Y_ANGLE_MIN = 5.0f;
    private const float Y_ANGLE_MAX = 50.0f;

    public Transform lookAt;
    public Transform camTransform;

    private Camera cam;

    [SerializeField] private float distance = 5.0f;
    [SerializeField] private float currentX = 0.0f;
    [SerializeField] private float currentY = 20.0f;
    [SerializeField] private float currentZ = 8.0f;
    [SerializeField] private float sensitivityX = 4.0f;
    [SerializeField] private float sensitivityY = 1.0f;

    private void Start()
    {
        camTransform = transform;
        cam = Camera.main;
    }

    private void Update()
    {
        // rotate camera view when right mouse button is pressed
        if ( Input.GetMouseButton(1) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A)) // TODO need to add A and D keys to also rotate camera        
        {
            currentX += Input.GetAxis("Mouse X");
            currentY += Input.GetAxis("Mouse Y");

            currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
        }
    }

    private void LateUpdate()
    {
        Vector3 dir = new Vector3(0, 0, -distance);
        Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
        camTransform.position = lookAt.position + rotation * dir;
        camTransform.LookAt(lookAt.position);
    }
}

If one can point me in the right direction to achieve this (these?) functionality, that would be awesome. What am I doing wrong or what am I missing at this point.

UPDATE:
for the first problem, I found the solution in this thread

add Cursor.LockState in the Update Method

private void Update()
    {
        // rotate camera view when right mouse button is pressed
        if ( Input.GetMouseButton(1) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A)) // TODO need to add A and D keys to also rotate camera        
        {
            //Lock cursor position and change it to "invisble" state
            Cursor.lockState = CursorLockMode.Locked;

            currentX += Input.GetAxis("Mouse X");
            currentY += Input.GetAxis("Mouse Y");

            currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
        }
        else
        {
            //when user lets go of mouse, resume normal cursor functionality
            Cursor.lockState = CursorLockMode.None;
        }
    }

01 The above code will “reset” the cursor to the center of the screen and make it invisible. I do not know how to make it turn invisible and have it stay put.

02 in the input manager under mouse Y axis click Invert. In unity 2018 its: Edit : Project Settings : Input, and it will be in the inspector.

03 The A and D keys are moving the player in the ThirdPersonUserControl.cs. (I think). That would need to be rewritten, it seams to really be for a controller, not a keyboard. I’ll take a look at this, because I like that functionality myself, but I will in no way guarantee that I will be successful.

I hope I helped.

1 Like

You can look at this also. I have nothing to do with it, just found it on a Google search. Maybe it will help.

https://www.zesix.com/?p=118

1 Like

thanks Jimmy2Guys, I will have a look at this.

Privacy & Terms