Search Unity

Cinemachine RTS camera

Discussion in 'Scripting' started by brainwoker1, Apr 12, 2022.

  1. brainwoker1

    brainwoker1

    Joined:
    Jan 6, 2022
    Posts:
    4
    Hi there. I'd like to implement an RTS camera for my project using Cinemachine. But I didn't find any about RTS cameras. I have 1 camera that follows a character when it moves. But when a character just staying, I'd like to control the camera to look around the map using mouse input. Any ideas on how to do that?
    Example games: XCOM; Gears Tactics;
     
  2. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    For a basic RTS camera there is no need to use cinemachine, create an empty then have your camera be a child of that empty, move the empty rather than the camera and that will give you the RTS/Top Down style of movement you're looking for. If you rotate the empty for example then the camera will follow it and so on, you can do all sorts with this method, if you want to smooth things out, then you simply code the camera to keep track of the empty position and rotation with lerping etc. the way you would do with other smoothing techniques.
     
    Gregoryl and brainwoker1 like this.
  3. brainwoker1

    brainwoker1

    Joined:
    Jan 6, 2022
    Posts:
    4
    Thanks for the reply. I tried it before, but I also need to use smooth effects of Cinemachine, like zoom to the character etc. I thought that Cinemachine is more innovated and performed than a standard way of camera movement (lerping; tweeting; etc.).
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You can create the empty game object as @Lethn said, but instead of adding a child camera, create a CM virtual camera with:

    Body = Transposer, binding mode = LockToTarget
    Aim = Do Nothing
    Follow Target = LookAt Target = the empty game object.

    Your move/rotate code should simply move and rotate the empty game object. The camera will follow automatically. You can adjust damping values in the camera. CM camera will also blend nicely with other CM vcams if needed.
     
    almagames, CyFy and Y_Beatle like this.
  5. Y_Beatle

    Y_Beatle

    Joined:
    Feb 20, 2018
    Posts:
    9
    I thought also about this way. But also thought there is more "clear" way from the "box". Anyway, thanks for the idea.
     
  6. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    This approach works great for pan and zoom for example normal RTS top down view, I just set the cam x rotation to 90 to point it down.

    But what about being able to rotate the camera from looking top down, to looking forward (eg. rotate the vcam on the x axis) while still following the pan and zoom? I get that I can rotate and lerp the vcam in code, but I can't figure out if there are any follow/target settings that will do this for me, by rotating the target instead of the vcam?
     
  7. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,861
    The thing about cinemachine virtual camera is that you can turn one off, and another on, and the system will transition between the two. So you can just set up multiple virtual cameras as you need and swap between them, and the actual camera will transition through them depending on the easing settings of its cinemachine brain.
     
  8. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Panning works great but rotation isn't working.

    I'm testing by manually rotating the target object in playmode, and the vCam does rotate around the target, but it remains pointing down the Z axis. I of course want the camera to rotate to face the direction the target is now facing, are there other settings to make that work?