Search Unity

Question Camera that moves smoothly with mouse movement:

Discussion in 'Cinemachine' started by Kich867, Jul 28, 2020.

  1. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    I've struggled pretty much all day trying to find a clear-cut solution to this. My expectation is that Unity offers this out of the box, because so many games function like this, but I don't know what I'm looking for. I've followed a ton of camera tutorials today, none of them end up achieving the goal.

    So here's a clear cut example of what I expect:


    That's Remnant: From the Ashes, on PC. It's a third person shooter, the crosshair is 1-1 with your mouse movement. If you look left or right, your character turns in exactly that fashion. You hold "W" to move, you can press "A" and "D" to strafe, but steering or rotation is done via the mouse. That's what I expect and want.

    My assumption is that Cinemachine offers this out of the box and I'm just unsure of what to look for, but if it doesn't, I'd be greatly appreciative if someone could guide me in the right direction.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,712
    Yes, Cinemachine offers this. Look at the AimingRig sample scene in CM 2.6.0.
     
  3. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    Thanks!

    Can you just clarify for me, is the intent that I put this into an existing project? When I load it up and hit play, there's nothing here.

    When I expand the Environment, its missing prefabs, the Instructions object is missing a script, the reticle is missing sprites etc. Is there a Readme or something I'm supposed to look at first?
     
    Last edited: Jul 28, 2020
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,712
    You need to import all the Cinemachine Samples into your project, then play the Aiming Rig scene. Don't just import the scene. Use the scene as an example of how to set up your character controller and camera in your own scene.

    You can also look at the 3rdPersonWithAimMode scene for an alternative approach.

    upload_2020-7-28_9-13-54.png
     
  5. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    Thank you! No idea how I missed that button, I ended up on your github and just downloaded the aimingrig scene!
     
  6. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    Two hopefully quick questions:

    1. The AimingRig sample, which is perfect by the way thank you again, the speed at which my character looks around doesn't match my mouses sensitivity. There is a "Turn Speed" property on the Character Movement No Camera script which influences this speed. Is this the expected way for a game to provide a sensitivity option to players?

    2. Also, the camera movement is very stuttered while panning around. Is there a solution to this in the project via some settings or is this something I'd have to tinker with the script to make this smooth and consistent with my own mouse movements?
     
  7. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    AimingRig uses 3rd Person Follow to determine position and rotation of the vcam depending on the follow target alone. This means, that the turn speed is equal to the turning speed of the follow target, not your mouse. If you setup your follow target to turn based on your mouse input, then the 3rd Person follow will indirectly match your mouse sensitivity.
    In our example, you can change the turn speed on the CharacterMovementNoCamera script on the 3rdPersonController gameObject to match your mouse movement speed.


    It should not stutter. The vcam follows the follow target, so if the follow target stutters, then your vcam will stutter too. You can change the Damping parameter under Body to make it smoother. But I would recommend fixing your follow target.
    Does the vcam stutter for you in our AimingRig example scene?
     
  8. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It depends. A lot of games provide sensitivity options along mouse axes (X, Y). Often, it is hidden as an advanced option.
     
  9. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    Sorry, can you clarify this for me a little? In the sample I only seem to be able to match the turning speed of the follow target. Turning off "CharacterMovementNoCamera" entirely disables mouse look. Is it possible to just straight up match my mouse sensitivity by default?

    Or is that not really a thing and I just have to adjust my Turn Speed to how I want it to feel? (I can add some kind of way to scale that later in options)



    Yes, this is a brand new fresh project, all I've done is install cinemachine, install the samples, opened AimingRig scene and hit play. The camera jerks quite a bit, its really noticeable if you bump the Turn Speed up to 15 or so but you can still see it at the default if you look closely, its just that the default moves the camera exceedingly slowly.

    It almost feels like the script needs my mouse to move a certain distance before it sort of accepts the movement? There's sort of a weird deadzone where I can wiggle the mouse and the camera does nothing, moving it any further and it skips in that direction.
     
    Last edited: Jul 29, 2020
  10. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Yes, because by disabling CharacterMovementNoCamera, the character does not rotate with mouse input. The third person camera is not moved by mouse input. The third person camera uses 3rd Person Follow body behaviour, which calculates position and rotation of the camera based on the position and rotation of the character (follow target).

    I don't think so. You have to play around with the Turn Speed option.

    Yes, you are right, good catch. ;)
    Change FixedUpdate to Update in CharacterMovementNoCamera script.
     
  11. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    Thank you, that does fix the camera smoothness. However, by changing FixedUpdate to Update here, we now move very slowly forward and strafe at speeds so high we clip through the wall and ignore the collision somehow.

    My instinct here would be to pull the camera controls / rotations out into Update and the character movement we keep in FixedUpdate? Or is it considered bad practice to use both updates on the same object?

    *EDIT* By doing so it seems to solve the problem. Having mouse controls and rotation in Update and character movement in FixedUpdate makes the character movement feel like you'd expect it to operate and the camera moves super smooth around the screen now.

    I'm assuming this is because the players movement is governed by the physics engine, which I had read is what you want to use FixedUpdate for, while Update just runs at the speed the game runs. So keeping movement in FixedUpdate lets the physics engine better handle its thing, and keeping the camera controls in Update keeps it smooth because its updating much faster(?).

    Thanks for the help all!

    For anyone curious exactly what I did: https://pastebin.com/jPUDKD5r
     
    Last edited: Jul 29, 2020
  12. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Yes, that's a possible solution, though I have not looked at it in depth yet. We are going to fix it and put it in our next patch.
     
  13. terrijaki

    terrijaki

    Joined:
    Apr 17, 2020
    Posts:
    5
    Hi all
    sorry but i haven't found any entry for this.
    :) i want to set a 360 degrees rotation and MouseWheel Scrolling (for Zoom) in the scene (everything with Mousebuttons). It works perfectly without Cinemachine with a script on my main camera. But when i set the cinemachine Tools to my scene, the script doesn't work any more:(
    Is it possible to rotate 360 degrees and zoom with Cinemachine?
    sorry for my english :oops:
     
  14. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    I'm not sure if you can help me with this, maybe this is what you're addressing in that fix, however if I move the camera movement and player rotation to Update, then leave the player movement in FixedUpdate, the model stutters heavily.

    After some research, it seems this is caused because FixedUpdate runs slower(?) than Update and without some kind of interpolation of the movement you'll have stuttering.

    I'm not quite familiar enough with how to solve this problem, do you have any suggestions?
     
  15. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Not yet. I encountered the same issue. And you are right, it is caused by FixedUpdate runs at a different fps than Update.
     
  16. Kich867

    Kich867

    Joined:
    Jan 12, 2018
    Posts:
    14
    My plan is to move all the movement code to Update and try to leverage some of the example stuff in this article with a Character Controller: https://medium.com/ironequal/unity-character-controller-vs-rigidbody-a1e243591483

    It probably won't work out of the box with this sample project though since, correct me if I'm wrong, the player is being moved by applying Speed to the animation? I'm guessing that because I don't really see any alterations to the Transform's position besides when we strafe left and right.
     
  17. ghanshyambista7

    ghanshyambista7

    Joined:
    Mar 30, 2020
    Posts:
    5
    Does Anybody Have Idea About Ads Aiming System Like Pubg using Cinemachine Virtual cam ?
    In This Aiming System Only the hands and weapon is Visible and Gun Is Pointed towards the Lookat Position.
    While I am trying to use ThirdpersonAim Extension of Cinemachine i am Unable to move Weapon towards AimPoint.

    Please Help.
     
  18. ghanshyambista7

    ghanshyambista7

    Joined:
    Mar 30, 2020
    Posts:
    5
    Do you Have Idea About Ads Aiming System Like Pubg using Cinemachine Virtual cam ?
    Switching From Third Person To This System ;
    In This Aiming System Only the hands and weapon is Visible and Gun Is Pointed towards the Lookat Position.
    While I am trying to use ThirdpersonAim Extension of Cinemachine i am Unable to move Weapon towards AimPoint.
    sorry for my English;

    Please Help.

     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,712
    @ghanshyambista7 The ThirdPersonAim component uses the position and rotation of a (usually invisible) player object as a guide for the camera. If you attach your gun to this object, and set the shoulder and arm offsets in the ThirdPersonAim to zero, then it should give you what you want.