Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Crosshair controlling free look camera

Discussion in 'Cinemachine' started by wolfulus, Jan 29, 2020.

  1. wolfulus

    wolfulus

    Joined:
    Jun 10, 2015
    Posts:
    12
    Wondering: is there a way to control a free look camera based on a crosshair moving over the screen?

    TBH I'm not even sure if free look is the right camera to be using, but I want to accomplish the exact same behavior as this:



    Basically the crosshair has a weight on the camera angle, keeping the player on focus. My first thought was free look camera as it rotates around the player.

    Any suggestions how to do that?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    This movement is quite complex, and would need a bit of thought and analysis to understand what's going on. You won't get it from CM out-of-the-box without a little custom scripting.

    Maybe you can start with a description of exactly how you want the camera to behave. That will help break it down into concepts, which we can then map to the CM tools.
     
  3. wolfulus

    wolfulus

    Joined:
    Jun 10, 2015
    Posts:
    12
    So, what I'm trying to do is having an object in the center of the screen, just like an free look camera has, having a way to go up and down, and so on.

    While this works, I'm trying to control the angle which the camera is facing, based on the position of an object so for example, if the object moves out of the inner bounds of the screen, the "free look" camera will rotate accordingly to keep that object inside the inner bounds. Just like the crosshair in the video I mentioned. The camera sits still whenever the object is freely moving inside the camera bounds, it's just when it goes out of bounds that the camera compensates (always keeping the player in the center of the screen).


    To illustrate:

    https://prnt.sc/qzeytj

    btw: I thought this way it could be easier because if I control the 3d object's location, I can use it as the crosshair location on the screen
     
    Last edited: Feb 8, 2020
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    Interesting. I would approach this with a virtual camera set up with a Framing Transposer in the Body, and Do Nothing in the aim. Follow Target is the player.

    Then, I would author a custom script which looks at the angle between vcam forward and the red player target. If that angle is outside the FOV then rotate the vcam until it's inside.

    The Framing Transposer will take care of orbiting around the player when you change the vcam rotation.

    If you get this to work, don't hesitate to post your solution here. It could make for a nice camera.
     
  5. wolfulus

    wolfulus

    Joined:
    Jun 10, 2015
    Posts:
    12
    I'll give it a try! Thanks for the suggestion!
     
  6. wolfulus

    wolfulus

    Joined:
    Jun 10, 2015
    Posts:
    12
    I got what I wanted with using only cinemachine, but there are some weird behavior.

    Player keeps jumping/stuttering/jittering on the screen, even though it's static (also odoesn't seem to respect the hard/soft zones), and aim doesn't seem to respect them too.

    Is this a bug? I wanted to have player (cube) always in that location (that's why I zeroed the zones on the body), and aim to respect the zones I've set (with just a little smoothing)

     
    Last edited: Feb 23, 2020
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    Nice job!

    The jittering is in fact a known issue when Composer is used with Framing Transposer. We have fixed this for the upcoming release of CM, so if you can ignore it for the time being, it will go away on its own when you next upgrade CM.

    I set up a similar scene, just to try it out. Moving the mouse outside the screen edges will rotate the camera. I gave the player a bit of a dead zone, just for fun, and added a little script to make its gun always point to the place in the world that falls under the camera reticle.

    We'll include this scene with the CM Samples.

    LoseAim.gif
     
  8. wolfulus

    wolfulus

    Joined:
    Jun 10, 2015
    Posts:
    12
    Hey! This is awesome!

    I'm glad I wasn't doing anything wrong in the end, I spent quite some time trying to get this right.

    I even thought the jittering was caused because aim needed to be updated before the body, and there was a sync issue there. While looking at the inspector you could see the camera jumping then adjusting the aim.

    Waiting for next release then! :))

    Thank you so much!
     
    Last edited: Feb 24, 2020
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    You're exactly correct: that is the problem when Framing Transposer is used. It needs to be updated after the aim.
     
    wolfulus likes this.
unityunity