Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Top-down shooter camera sliding towards mouse

Discussion in 'Cinemachine' started by Mystic_Quest, Oct 17, 2018.

  1. Mystic_Quest

    Mystic_Quest

    Joined:
    Feb 22, 2016
    Posts:
    32
    Returned to Unity after some time and been toying with Cinemachine a bit. Got a top-down 3d shooter (60 deg perspective) with the player aiming at the mouse. Added a virtual cinemachine cam for gameplay (not even sure if it was the right one to use), set it to follow and aim the player, adjusted some settings so that the camera doesn't rotate at all and I got a working camera.

    Now I want to make it slide towards/follow the mouse position (where I am aiming at) up to a point, like in many top-down shooter games and have a deadzone near the character to avoid small camera movements. Any idea if that's possible with cinemachine? Don't know where to start.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,731
    Hey @Mystic_Quest Sorry for the long delay. This post fell off my radar and I just noticed it again.

    The Framing Transposer is designed primarily for 2D use, and as such isn't perfect for the situation you describe. That said, it is possible to get pretty close, with a little tinkering. I tried it out, and am including my results in the attached package. Create a new project, add Cinemachine from packman, then drop this in and open the scene. When you play it by using WASD to move the player around, the camera follows at a more-or-less constant height, with a dead zone in the center. That's what you're looking for, right?

    Here is how I set it up. You have to first set up your vcam with the Framing Transposer and the viewing angle (60 degrees, in this case). Then, put in the desired camera distance, and the dead zone height.

    Next, run the scene. When you move the player back and forth, the camera will move up and down in Y to maintain the target distance. You don't want that, so here is where the tinkering comes in. You have to set the dead zone depth just right to neutralize the vertical movement - and that amount will depend on the specific camera distance, angle of view, and dead zone height.

    upload_2018-10-29_14-35-28.png

    What I did was to move the player back and forth so that it reached the top and bottom of the dead zone, and keep an eye on the camera Y position in the inspector. I then gradually adjusted the dead zone depth until the Y movement disappeared, or was sufficiently negligible. And that was the value I kept.
     

    Attached Files:

  3. Mystic_Quest

    Mystic_Quest

    Joined:
    Feb 22, 2016
    Posts:
    32
    Hello, no problem and thanks for the reply!

    Ah it seems the framing transposer was in 2.1! Still had 2.0. At any case, was looking for a way to handle the camera only with cinemachine without any scripting and was looking for a way for it to "gravitate" towards the mouse cursor when it gets far enough from the player.

    Managed to do it with a bit of scripting (executable if you wish to see it: https://www.dropbox.com/s/zxsqwqnaiznpss5/test.rar?dl=0).
    Lerp'ed between raycast cursor and player vectors with 0.3 weight, placed an empty object for the vcam to follow.

    Only problem atm is that I wanted the camera's movement damping to happen only when I move it with the mouse (and also have a deadzone), not with the player movement, which is not possible the way I did it (or any other way that I know of). :p
     
    Gregoryl likes this.