Search Unity

Cinemachine Collider slips off aiming point

Discussion in 'Cinemachine' started by NotoMuteki, Mar 5, 2019.

  1. NotoMuteki

    NotoMuteki

    Joined:
    Feb 8, 2018
    Posts:
    42
    I'm using Cinemachine FreeLook to create TPS over the shoulder aiming camera.
    I was using CinemachineCameraOffset component to stay camera in the right of the player,
    but as @Gregoryl mentioned here:
    https://forum.unity.com/threads/third-person-shooter-over-the-shoulder-camera.525385/#post-3457253
    CinemachineCameraOffset doesn't work well with CinemachineCollider(Camera goes through the wall when it hits the wall on its right side).
    So I decided to change the approach, set Screen X to 0.2 in all rigs.
    That fixed collider going through the wall but I've got another problem.

    When the camera hits the wall and pulled forward, the center of screen slips off the original aiming point.
    ua1.PNG
    ua2.PNG
    This gives really bad user experience, because players must fix aim every time when their camera hits the wall.
    When I used CinemachineCameraOffset this didn't happen.
    My best wish is CinemachineCameraOffset works with CinemachineCollider, but currently it doesn't.
    Is there any way to keep the center of screen staying same when the camera hits the wall?

    FreeLook setting is like this:
    setting.png
    I've attached the project to demonstrate what I'm trying to say.
     

    Attached Files:

    Last edited: Mar 5, 2019
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Since you're rotating the player to always face camera forward, there is a simple solution:
    1. Create an invisible child of the player to serve as a camera target. Place it to the right of the player, in the position you want.
    2. Set that as your LookAt and Follow targets in the FreeLook
    3. Always aim exactly in screen center, all 3 rigs
    4. Set the CM collider mode to Pull Forward (you have that already)
    I've done that in your scene and attached it here.
    Also: I fixed your controller script to rotate the character after the camera is updated. That eliminates the flicker.
     

    Attached Files:

  3. NotoMuteki

    NotoMuteki

    Joined:
    Feb 8, 2018
    Posts:
    42
    Thank you very much!
    That's exactly what I needed.

    But only one thing:
    When the child object goes through the wall, CinemachineCollider does not work.
    sc1.PNG
    I think this is because the child object is "inside" the collider so raycast couldn't catch the wall.
    I will have to write script to avoid the child object going through the collider.
     
  4. NotoMuteki

    NotoMuteki

    Joined:
    Feb 8, 2018
    Posts:
    42
    Hi @Gregoryl ,
    Slipping off the aimpoint is solved thanks to you, but I've bumped into another problem.

    When CameraTarget gets too close to the camera, it starts jittering.
    Is there any way to fix this?

    I've attached a script to CameraTarget that raycasts back and right and if there's something moves CameraTarget little forward and left.
    It's fine with flat collider, but when it bumps into thin collider such as pillar, still starts jittering.
    So I don't think this is the best solution.
     

    Attached Files:

  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Yeah, you'll never be able to get the jitters out with this approach, I should have noticed it earlier.

    The problem is that you've set up a feedback loop: mouse -> Camera -> player -> Camera -> player ->.... and with the collider perturbing the camera there will always be situations where that loop goes around forever.

    What you need to do is something more like this:
    1. Make the mouse control the player directly, NOT the camera
    2. Position the camera relative to the player

    So, get rid of the FreeLook, replace it with a simple vcam with transposer, composer, and collider.

    Have your character controller script directly apply user input to the player. Let CM figure out where to put the camera, but the camera transform should NEVER affect the player transform, or you expose yourself to these infinite loop jitters.
     
  6. NotoMuteki

    NotoMuteki

    Joined:
    Feb 8, 2018
    Posts:
    42
    I've deleted FreeLook and made new simple Vcam, set to look at CameraTarget(slightly right of the player).
    And changed the controller script to rotate the player directly from mouse inputs.
    That solved jitters perfectly. Thanks a lot.

    For the people trying to create over-the-shoulder TPS with Cinemachine, here's the package of result.
     

    Attached Files:

    Gregoryl likes this.