Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta 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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

to decide the character moving direction during/after camera blend

Discussion in 'Cinemachine' started by canis, Oct 5, 2018.

  1. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    41
    I'm not sure where should I ask this question,
    probably already have the answer, but I can't find the keyword for these problem.
    and... sorry about the English :D

    As the title describe, my game is 3D base, action game.
    and I'm using the camera to decide the player moving direction.
    by project the camera forward on ground normal.
    Code (CSharp):
    1. // based on avatar current standing plane, to calculate the cameraForward.
    2. private Vector3 groundNormal = Vector3.up;
    3. public Vector3 CameraForwardOnPlane { get { return Vector3.ProjectOnPlane(Camera.main.forward, groundNormal).normalized; } }
    4. public Vector3 CameraRightOnPlane { get { return Vector3.ProjectOnPlane(Camera.main.right, groundNormal).normalized; } }  
    The real problem is it's not accurate (on player perspective).
    consider the situation we using the TPS camera placed on character's shoulder, the final vector will have a small amount angle offset.
    as a result, we input forward, character will end up moving in arc instead of straight line.

    Q1) here is the question is that a way to avoid that small angle offset ?
    my first attempt is Vector3.Dot, setup a threshold to auto correct the angle, but it result in inconsistent movement.

    and then the 2nt attempt is adding a angle correction offset for the `CameraForwardOnPlane` (code above), but how can I define the correction offset ?! (Ignore me if I'm wrong)


    ------------------------------------------------------------
    The problem will become critical when we trying to using Cinemachine to style our final result.
    assume we still want player have a limited control !
    the origin forward no longer THE local forward of character (because the camera position changed.)
    how the movement getting invoked during camera blending.

    E.g.
    using Unite Europe 2017 demo. 19:37

    I believed the speaker had the same issue ? seem like the character turn a weird angle after camera changed.

    E.g. Shadow of Tomb raider's QTE cutscene. 50:00

    this game QTE cutscene is the reason why I'm asking this question.

    Q2) Is that all scripted ? and override the input direction based on demand. (QTE)
    Q2.A) if (scripted), any advice to setup the system ? aim to speed up the level design setup.
    Q2.B) if (not scripted), how can we solve the angle offset during/after blend - like 90 degree on Europe demo.

    hope someone can share more information, many thanks.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,649
    Very good question.

    One way to do it is this: player movement is always in player-space, never in camera-space. So forward is always player-forward. That way you never need to account for any camera angle difference.

    In the Unite demo, there seems to be 2 modes of operation:
    1. when FreeLook is active (and not blending, unless to another FreeLook): player forward is synched to camera forward, then movement is applied in player-local space. Synching can be instantaneous, or gradual (with damping).
    2. when blending, or in a non-TPS camera (e.g. cutscene): player forward is NOT synched to camera forward. Movement is still in player-local space.
    Your player controller needs to be aware of when character forward has to be synched to camera forward before moving the player. Maybe you could do this with a custom script on the vcams to push this setting, or by tagging vcams in a certain way, and having your controller look at the current vcam tag and the blending state (these can be accessed via the Brain on the main camera) before deciding how to apply the movement.

    Does that make sense, and does it answer your question?
     
    canis likes this.
  3. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    41
    yes, It does make sense, I need to made a script to define the correct angle, instead of player/camera forward
    however, can you explain more about this solution ?

    I'm not sure which parameters I'm look for.
    is that about Clean shot & active v-camera ?
    seems like I didn't get the full picture here. (how to solve that with vcam tag & blending state?)

    PS: the always player-space is one of the solution, just not suitable for the control that I'm using.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,649
    1. Modify your player controller so that forward movement is always relative to player rotation, never to camera rotation.
    2. Additionally, before applying the movement to the player, the controller might need to rotate the player in order to align it with the camera. You need to devise a means for the controller to know whether it has to do this.

    First of all, you said that this idea won't work for you. Why not?
     
  5. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    41
    Sorry, my mistake, seem like we had communication problem, let me give you more information.
    and I understand it's not an easy task. only to solve those issue for hobby.
    not forcing anyone to help, but appreciate any discussion.


    As the title said I try to create the control in 3D action game. the game is about shooting & melee attack.
    here is what I'm thinking. (May be I get something wrong in first stage, did I ?!)
    1. usually game-pad have 2 thumb stick (Left/Right analog control)
      1. Left = movement
      2. Right = Camera movement
    2. during battle, I assume player will focus on combo chain or shooting process.
      So most of the time the player won't have the time to adjust camera angle.
    3. try to solve camera sick,
      reduce unnecessary camera movement that may break the feeling
    for the movement control, my thought is player usual wanted the full control of camera,
    but something they just want the camera to be smart { don't follow or follow }
    the cases I observed via the other games. and got the following list.

    Red = with camera angle changing.
    Blue = no camera angle input from player.
    • Idle - just standing, I don't care.
    • Idle - probably try to screen shot.
    • Moving - 100% player control.
    • Moving forward (away the camera), follow & re-centering to keep align player moving direction.
    • Moving aside (dash left/right), player trying to shooting, dodge enemies attack. keep current camera direction.
    • Moving backward (toward camera), don't move camera, re-centering will result in chasing your tail.

    to solve the above problem, I try to modify the re-centering process last time.
    Ref: cinemachinefreelook-adjust-recentering-during-runtime
    the condition & mechanism are simply

    Code (CSharp):
    1. float dot = Vector3.Dot(moveDir, camDir);
    2. bool allow = dot > 0.5f; // within 45degree to forward
    and then apply different re-centering parameters.

    here is the result in video
    first 0 ~ 20 sec, I didn't manually change camera angle. it's re-centering & script control.
    so than I can free my hand to do something else.

    the problem we discussing.
    at 0:46 sec
    I setup another clean shot within that room, want to create some kind of CCTV effect.
    the bad UX: player run toward to the wall...everytime after camera blending.