Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Cinemachine RTS camera

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

  1. brainwoker1

    brainwoker1

    Joined:
    Jan 6, 2022
    Posts:
    2
    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,584
    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:
    2
    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:
    6,006
    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.
     
    BrainWoker likes this.
  5. BrainWoker

    BrainWoker

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