Search Unity

Setting Free Look's aim direction

Discussion in 'Cinemachine' started by sevensixtytwo, Jul 5, 2019.

  1. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Hello all

    I'm currently trying to polish up some cinematics. Unfortunately, I seem to have a problem with the transitions.

    So I'm transitioning from a virtual camera (that's looking at the player) to a free look camera (that uses POV and following the player). I am setting their priorities in order to accomplish this. From here, once the transition completes, the player's camera returns to what his view was before the cinematic was started (ie, pointing above, left or even behind).

    My objective right now is to have the player's camera pointing in the same direction the player unit is facing once the cinematic finishes. The first thing I did was enable recentering on both axes of the FreeLook camera when the cinematic begins. It did result in the camera facing the same direction at the end of the cinematic, but the camera would actually transition towards world Z vector before snapping to the proper direction in a single frame.

    Video:


    I tried a couple other things:
    1. Enabling recentering on all the FreeLook's child rigs (No noticeable effect)
    2. Enabling Inherit Position on the FreeLook's Transitions options (No change in behavior, although it does randomize the end direction if the recentering changes are reverted
    3. Set FreeLook's Standby Update option to "Always" (No noticeable effect)
    From observation, it seems as if the FreeLook's child rigs' POV values aren't being updated during the transition. Using the video as reference, you can see that the FreeLooks main X axis value is 90.0001 while the child rigs are stuck at 0 (recentering is enabled). Then the child rig values snap to the main value when the transition completes. I've attempted to change the child rig values in the inspector during the transition but they revert to 0 on the next frame (both with and without recentering enabled).

    Is there any way I can work around this and achieve the effect I need? Or am I going about it wrong and there's actually a much simpler solution for it?

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's very unusual to use POV with FreeLook, and it's not a case that we've really tested over here.

    What is your LookAt target in the FreeLook? The InheritPosition uses that to figure out where to put the camera, relative to the target, and the Composer is expected to aim there. With the POV, all bets are off.

    Why are you using that combination instead of just the normal FreeLook?
     
  3. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Hello. I use this strange combination due to the way I need the camera and player to interact. Instead of turning the player and the camera following, the camera rotates independently around the player who then turns to "catch up" to the camera's current rotation. On the other hand, the camera rigidly follows the position of the player + offset.

    I built the rig way back in Unity 2018, I think, but I recall that without using the POV and adding to the main X Axis Value, the camera would continue facing in one direction even as it orbited around the player. I also used the Heading Bias variable to control the shoulder offset because the Offset extension did not work with the Collider extension. The Camera, FreeLook and VirtualCamera objects are also not parented to the player.

    I don't have a LookAt target in the FreeLook. Is a LookAt target required?

    In any case, it's all working splendidly aside from the issue above.

    Feature:


    upload_2019-7-5_22-54-41.png
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    So you're just trying to implement an over-the-shoulder FreeLook camera? POV really seems like a strange move. Have you just set the POV axis values at some fixed quantity?

    I would suggest that you try again with a more traditional approach, with composer and a LookAt target. The latest CM has an improved CameraOffset extension - it also offsets the LookAt target, so it should play better with collider. If you go that route then your blends should work properly out of the box. Having a valid LookAt target is an important hint for CM.
     
  5. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    At your suggestion, I redid the FreeLook using a LookAt target and Composers for the rigs. I got it working relatively close to my old view and it now does recenter during the transitions, but it came with some caveats.
    1. The LookAt forces me to use the CameraOffset extension since the camera will always look at the target regardless of HeadingBias.
    2. This results in CameraCollider extension only kicking in if the obstacle is directly aligned with the player and not the camera
    3. When the CameraCollider moves the camera due to an obstacle, the LookAt makes the view move without any input from the player
    4. Due to camera follow being damped, the view gets yanked and pulled around when the player moves with any speed or jumps. Strafing actually makes you move in a circle due to the camera tilting towards the LookAt target. Increasing the Deadzone in the rigs leads to some janky looking screen offsets when combined with the weird CameraCollider behavior.
    For comparison:

    Old (POV) behavior


    New (Composer) behavior


    I did not try to move the view at all in either of the videos, just purely moving and jumping around. Manipulating the view feels the same in either configuration, for which I'm grateful.

    I do feel that this is a step in the right direction with regards to working with Cinemachine. Maybe there are some techniques that I may not know to deal with the above issues?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    What CameraOffset extension are you using? The one posted in the forums, or the one that (now) is shipped with CM? I ask because the behviours are a little different.

    If you're using the one shipped with CM, then your #2 should not be an issue.

    For #3, I'm not exactly sure what you want the camera to do. If it moves due to an obstacle, the view will necessarily change unless it happens to move exactly along the camera's z-axis. What is the behaviour you're looking for?

    For #4, again, with the Offset extension shipped with CM, there should be no camera tilt towards the LookAt target. For the jumping, could you put more Y damping than X damping?

    Maybe you should show me pictures of the vcam inspector.
     
  7. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Hello, and thank you for your continued support.

    I am using the extension that is applied from the dropdown menu at the bottom of the Cinemachine FreeLook component. My Cinemachine package is updated to 2.3.4 in the Package Manager. I am using Unity Editor 2019.2.0b5.
    upload_2019-7-8_22-51-17.png

    Here is a screenshot of the settings:
    upload_2019-7-8_22-54-48.png

    The "cameraTarget" object is a child of the player object.

    upload_2019-7-8_22-56-17.png

    The rigs all have identical settings with slight changes in offset. The Body damping values are changed at runtime through in-game options (from 0-1).

    Extensions:
    upload_2019-7-8_22-48-2.png

    The LookAt target offset works fairly well, I'd say. it's just that the offset also moves with the LookAt target, so the camera "look" still occurs due to follow damping.

    While I do intend for the position to change with the CameraCollider (discounting how it ignores the CameraOffset), I'd really like it if it didn't jerk to look at the player when it gets shifted closer. Movement input is translated to the camera's local space. If the player moves/jumps with camera follow being damped or it gets yanked about by the CameraCollider (when it works), the camera view gets centered towards the LookAt target. This causes the input to translate into a turning motion because the camera is no longer looking in the original direction.

    I simply want the camera to retain it's original orientation when my character is moving around the screen. In short, it shouldn't "look" at anything or even budge unless the player does so. Please refer to the videos in my previous post.

    I have tried playing with the Composer settings (specifically Deadzone and Damping), but they lead to strange behavior when combined with the CameraCollider (ie, offset shifting like the player going off-screen and staying there)

    Thank you again!
     

    Attached Files:

  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Ok, I get it that you don't want the camera to rotate without user intervention. So I would ask: why are you using a FreeLook instead of a simple vcam with a transposer? What should happen if the user rotates the freeLook around to the other side?
     
  9. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    I did assume that FreeLook was the sort of camera rig that "doesn't rotate without user intervention." Was I mistaken?

    In any case, the three-rigs-on-a-curve + orbit features of FreeLook are very desirable for my game. I'd hate to have to manually recreate them on another vcam base. :(

    I don't understand the last bit. Wouldn't the camera just orbit around to face the other side?


    I can say with confidence that it does behave exactly like my old POV-based rig, at least up until the player starts moving.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Let's say the player is facing north, and moving in that direction. The camera is following behind, looking north at the player. Now the user, with the free look, obits around to be in front of the player. Unless the camera has been somehow instructed (either by the user, or by using a LookAt target with a composer or some such), the camera will continue to look north, and not see the player at all. Is that what you want?
     
  11. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Yes, that is exactly the issue that caused me to decide on using POVs. If you'll refer to my second post on this thread, that is the behavior I encountered when trying to use FreeLook without a LookAt target. Now, I update all the POV components' axes to match the values on the main freelook and it works. No yanking or jerking.

    On the bright side, I found that I needed to force POV update during the transition (since it's usually only on input, a major oversight on my part), so my initial problem is solved with the POV-based Freelook as well.

    I guess I was surprised you mentioned Freelook and POV haven't been really tested together, so I immediately assumed that what I had done was hacky and unsafe. I am interested if there is a way to get the behavior I need from Cinemachine "as intended" seeing as it is conceptually a very simple requirement.

    Thanks again.

    Gameplay sample using POV-based rig:
     
    Last edited: Jul 9, 2019
    chelnok likes this.
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The camera certainly looks nice in the video, congratulations!

    I'm still having a little trouble understanding exactly what your requirements are. If you don't mind and can spare the time, I'd like to drill down on it a little more. If there's an important use-case that we haven't covered adequately, I'd like to address that.

    I don't really understand the relationship between the camera position and aim. It's not clear from the video what controls the user is manipulating and when. Contrary to your description, it doesn't look like there is a fixed offset between character and camera.

    Would you be willing to export a simple scene containing your camera rig and a dummy player that can be controlled, and send it to me? I'd love to get a deeper understanding of what you're doing.

    Thanks
     
  13. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Thanks!

    The offsetting isn't really a main issue, since I also have a setting with the player centered, and the offset direction gets switched when the player moves laterally. I also saw those other threads where the CameraOffset extension's foibles with the CameraCollider were discussed.

    I also have a scale-able auto-sight mechanic where the camera gravitates towards a locked target. Using a Composer-based rig conflicts with it because the main rig is trying to sight the enemy while the child rigs keep looking at the player+offset. On that note, I actually credit that auto-aim system to your answer on my previous thread which I was unable to reply to as I had lost my password during that time period. A belated "Thank You Very Much" is in order.

    I am currently unable to cut out a demo of the player rig due to a lot of the settings needing to get initialized in options. I'll try to slice out a quick isolated version over the weekend. Thanks for the interest.

    The main thrust of the rig is setting the child rigs' POV components to follow the main rig as shown here:
    upload_2019-7-12_12-45-12.png
    The FreeLook's Y-axis takes a value from 0-1 while the POV components require degrees(?) hence the computation.

    I had previously only had this part running when input was detected, but allowing it to run during "cinematic mode" solved the issue in my original post.

    Here's a graphic I wrote up that lists down the behavioral differences I've found between the two:
    upload_2019-7-12_12-40-19.png
     
    Last edited: Jul 12, 2019
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thank you for that explanation, and for sending the project. Although there were many "missing" scripts, I think I have a better understanding now of what you're doing.

    I'm finding myself agreeing with you that the POV / FreeLook combination is a better solution for this. I hadn't understood before how you were manipulating the bias. Thanks again for your effort in preparing this, and for the interesting use case!

    Feel free to reach out if you have any more questions/observations.
     
  15. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    I'm glad I was able to help even a little, given how much help you devs and these forums have been ever since I started.

    I'll be sure to do so.
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Taking a second look at your project.

    Noticed a big anomaly: you have the camera and vcams parented to the player. That's not a good idea. The camera wants to animate its own position via the vcams, and when you parent to the thing it's trying to follow, you create an unstable feedback situation. That might well be the source of the juddering in your scene. Certainly it makes the logic fragile and difficult to understand.

    I would take the camera and vcams out of the player, and make them their own GameObjects, like this:

    upload_2019-7-15_14-14-17.png

    Next, I was thinking about your POV + FreeLook solution, and the bias adjustments, and all the work you have to do to keep the thing stable, and wondered if there wasn't a simpler and more efficient solution. So I tried a radical simplification, and replaced your FreeLook with this:

    upload_2019-7-15_14-25-30.png

    Seems to works quite well out of the box, with no custom scripts at all. Would you be willing to test-drive that approach and let me know how it works for you?
     
  17. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Hello,

    The Camera and VCams are unparented in the InputPlayer script's initialization. I had them as children of the Gameobject as part of a prefab which I had to unpack when I sliced out the demo. Had to remove UI assets and such to keep the project size down, unfortunately. (I kept the audio for kinesthetics :D)

    upload_2019-7-16_9-53-0.png
    upload_2019-7-16_9-48-35.png

    I'll try out that set up and get back to you soon. Much appreciated!
     
  18. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Back with the project. I tweaked the settings a bit to get it closer to how my original rig looked like and the setup feels very good, especially with the smooth handling of the offset. At 0 body damping, it's almost perfect.

    upload_2019-7-16_11-1-8.png



    It gets a little jerky when damping is active, unfortunately. The camera doesn't orbit cleanly around the player. Like there's this noticeable yank once you stop moving the view. Seems like even the orbit movement is being damped, rather than just the follow movement, and it's tailing behind the camera view.





    At 0:50 the camera suddenly pulls close if I shift the view to the right while boosting forwards. It's a little disorienting. After tweaking the player's mobility to match my expected highest threshold (x1.5), the problems are significantly more noticeable.

    An issue occurring on both settings: When looking upwards while grounded, the camera will close in on the player's backside (due to the camera collider) and take a few seconds to adjust away from the player. It takes significantly longer when damping is active. First video, time 0:38.

    I also might need to increase the height of the camera when the player moves into the center to clear the FOV, but only if it stays there for a while. Playing around with the Framing Transposer settings, seems like the only variable that affects it is CameraDistance, which shifts the entire view backwards and up. Alternately, I could edit the cameraTarget's local Y pos. I also don't know how to figure if the player is in the center. This is just a nice-to-have.

    All in all, it does feel more like a conventional TPS camera, and the behavior when not damped is pretty ideal. Unfortunately, I do want to retain the damping as an option due to it mostly being a result of tester feedback. I'm actually fine with losing sight of the player mech if the speed is sufficient and compensate for it by adding a damping slider so players can adjust to taste with regards to their stats.
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Hey, thanks for taking the time to look at that. I appreciate your feedback!

    Yes, that's exactly right. The Aim POV changes the rotation after the Framing Transposer adjusts the position, so there is indeed a little lag because the framing transposer's output is a function of the rotation. I see the yank you're talking about. Not really sure what that is, it might have to do with the 1-frame lag. I will investigate that.

    The orbit movement is indeed damped, due to the AxisState input algorithms. It's possible to override those to get more direct control. There is a thread about this: https://forum.unity.com/threads/cinemachine-and-framerate.529992/#post-4632451

    What are your damping settings when you see this?

    This is a collider thing, because the Framing Transposer is trying to put the camera at the distance you set. Can you adjust some settings on the collider to prevent this? Maybe set it to Prserve Distance, or you could increase the collider's minimum distance from target setting.

    By height, you mean the Y position? You have it set very low. The distance setting shouldn't move the view up. It just moves the camera along its Z axis. The Framing Transposer makes 2 camera moves: first along its Z axis (damped with Z damping) to put the character at the right distance (on that axis only). Then, it moves in the XY plane to make the framing (again, damped according to the XY settings).

    We should be able to get the damping to work without hiccups.

    One question: in your tests that resulted in these videos, are you doing any script-based manipulation of any vcam settings, or do you just set it and leave it?
     
  20. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I had a look at yank thing. Current theory: it's the collider.
    Can you test this: disable the collider and see if thee's still a yank.
    Second test: enable the collider, but set its camera radius setting to zero. Is the yank still there?
     
  21. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Hello,

    If referring to the yank when looking around, I think it's mostly due to the Framing Transposer Soft Zones and damping.

    NOTE: My Unity Editor gets stuttery if I have an object selected while in Play mode, but it's buttery smooth without anything selected.

    I usually test with all damping values set to 1.0 (This is the max damping value I had with the POV FreeLook)

    Cinemachine guides enabled. Collider disabled. Damping is enabled after 0:15.

    Moving around with guides and damping enabled and no collider.

    The yanking seems consistent with the cameraTarget leaving the Dead Zone and hitting the Soft Zone with damping enabled.

    Adjusted Dead/Soft Zones with damping.

    Here, I tried adjusting the zones to keep the orbit stable while looking around but it's got some terrible snapping when moving.

    I think the main issue here is that the Transposer also dampens the movement of the camera around the player. It is very noticeable in that the camera pivots on it's own axis towards the new heading, then moves to maintain the framing. This movement is then affected by the dampening, which causes the orbit to lag behind the look.

    The FreeLook handles the orbit separately from the follow which is the behavior I'm looking for. It's also a lot less strict with the player exiting the frame.

    RE: camera distance


    Changing the Transposer's camera distance value seems to move my camera back and up. I also move the cameraTarget up and down in the latter half of the clip.

    RE: Code stuff
    upload_2019-7-17_10-49-1.png

    I drive the POV InputAxisValues through the InputPlayer script because I process the axes for a custom deadzone implementation.

    I really appreciate your taking the time to help me with this. It's also letting me play with Cinemachine settings that I normally wouldn't touch.
     
    Last edited: Jul 17, 2019
  22. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    UPDATE: Playing around more with the Transposer setting and finally got some behavior that's pretty close to what I used to have.

    Maximum Soft Zones and Collider enabled


    FreeLook POV for comparison


    The only obvious difference left is that the camera obviously pivots around itself and then adjusts to maintain offset rather than a true orbit.

    In terms of long-term experience, the Transposer does a better job in general movement and looking around due to how it handles the offset. If the camera target doesn't exit the Dead Zone, the camera remains stable. The shoulder switching is handled automatically via Zones and feels very natural.

    On the other hand, the FreeLook POV rig always moves with player and lacks a built-in way to handle shoulder switching so I had to cobble one together myself, which is obviously janky and doesn't scale well at all with the damping. I'll definitely have to improve that.

    Also tweaked collider settings. It does insist on keeping the player on-screen all the time, but it doesn't snake up to their backside anymore. It just clips through the floor instead. o_O
     
    Last edited: Jul 17, 2019
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I think it's looking pretty nice. I actually prefer the rotate-then-reframe approach over the orbit. I think it's closer to what a real cameraperson would do. The orbit thing feels nonphysical to me, and takes me out of the experience. But that's just my personal opinion.

    I saw that your collider has a camera radius set to 3. That's pretty darn big.

    There is still the issue of the Framing Transposer using stale rotation data, due to the ordering of Body and Aim. I've done a little work over here to implement an alternative POV, as an extension rather than as an Aim component, so that it can be applied before the Framing Transposer. I'm getting some nice behaviour with that in my test scene. It did require some infrastructure change (allowing extensions to intervene before Body), so I can't give it to you without also giving you a new version of CM.

    What version are you using now, BTW?

    For the distance setting: it's as I said, the camera moves only along its (local) Z axis as the distance changes. It's going up in the world because your camera is rotated to look down, and because your look-at point is placed low down on the screen, so the camera has to move up to keep the desired framing.

    You might want to consider moving the camera target so that it's closer to the center of your character. You might have an easier time that way with the settings.
     
    Last edited: Jul 17, 2019
  24. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Yeah, that did it.



    Looks pretty good, and I can live without the orbit if it cuts down on the complexity by a lot.

    I think I'll make a build with this system in place, see how the testers like it. I'll have to rewrite a lot of the options and the auto-aim but version control is a godsend. Thank you very much for your guidance on this subject!

    Also, I'm still on Cinemachine 2.3.4 as before.
    upload_2019-7-18_10-50-35.png
     
    Gregoryl likes this.
  25. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    Haha, I spoke too soon. So I integrated the Transposer into a build and initial testing around the main gameplay is pretty satisfactory. On deeper testing with the other systems, I found that if the POV component is set to recenter, it recenters relative to the world, not to the VCam's follow target. Back to original issue, I guess.

    I can just set it's Axis values to the player's Euler angle values either when the cinematic starts or during one, but maybe there's something simpler I'm missing that'll let the POV constantly recenter relative to its follow target?

    This works well enough, just so it doesn't snap:
    upload_2019-7-18_13-13-52.png
     
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yeah, you'll have to recenter manually :(
     
  27. sevensixtytwo

    sevensixtytwo

    Joined:
    Apr 5, 2013
    Posts:
    27
    I see. Oh well. Main issue solved and I got a spiffy camera setup out of it. Calling this one a win.

    Much thanks again!