Search Unity

FreeLookCamera WASD movement

Discussion in 'Cinemachine' started by Patrick_Rainer, Dec 22, 2019.

  1. Patrick_Rainer

    Patrick_Rainer

    Joined:
    Feb 26, 2018
    Posts:
    49
    Dear colleagues

    I am working on camera system for my building game. I use a free look camera and everything is going fine, except the WASD movement of the camera. I am not sure how to solve it.

    As you can see on the picture, the camera moves from a top down view until to a very near at the bottom view. Works just fine by the mouse wheel.

    Now i want to move the camera with WASD. Curently i am using the offset for this. In the very top position this works just fine, but in all other position the offset follows the angle off the camera. I would like to move the camera always in the same direction in relation to the screen like in the green boxes.

    How can I achieve this?


    upload_2019-12-22_16-51-43.png

    upload_2019-12-22_16-57-40.png upload_2019-12-22_16-58-16.png

    Code (CSharp):
    1. private void CameraMovement()
    2.     {
    3.         Vector3 currentOffset = myOffset.m_Offset;
    4.  
    5.         // Move Camera Horizontal
    6.         myOffset.m_Offset.x = currentOffset.x += Input.GetAxis("Horizontal");
    7.  
    8.         // Move Camera Vertical
    9.         myOffset.m_Offset.y = currentOffset.y += Input.GetAxis("Vertical");
    10.     }
    I know it's a long post. I hope somebody can help. Thank you.
     
  2. Patrick_Rainer

    Patrick_Rainer

    Joined:
    Feb 26, 2018
    Posts:
    49
    Ok, getting no answer so far. May be another view on the problem. What would be y(offset)?

    upload_2019-12-24_10-50-18.png
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    @Patrick_Rainer Sorry for the delay, end-of-year holidays got in the way.

    I'm having a little trouble understanding what you're trying to do. Can you give me a little context, and describe in words what your camera is doing in general, and then what you want the WASD to do?

    Right now, you have a FreeLook, looking at something. What is that something? When you press the WASD, do you want that something to move, so that the FreeLook moves with it? That is the usual method. I don't understand what you are doing with the Offset component.
     
  4. Patrick_Rainer

    Patrick_Rainer

    Joined:
    Feb 26, 2018
    Posts:
    49
    Sorry it's hard to describe.

    If I use the free look camera, which is setup to like above. When I change the value of the y-axis or the x axis the camera rotates with it to look on the target. I would like to have a dimension where the x and y axis are not rotating with the camera. For this I used the offset, but may be this is the wrong way.

    upload_2020-1-6_19-23-42.png
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Why don't you get rid of the CameraOffset and create an invisible target and move that when WASD is pressed?
     
  6. Patrick_Rainer

    Patrick_Rainer

    Joined:
    Feb 26, 2018
    Posts:
    49
    I already prototyped this. I remember there was some strange behavior with the "aim to" behavior. But may be I have to have a look on that again. I will try and let you know if it works.