Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Switchting between vcams on different targets positions the vcam behind the object?

Discussion in 'Cinemachine' started by xyzwqmf, Sep 13, 2020.

  1. xyzwqmf

    xyzwqmf

    Joined:
    Jul 27, 2020
    Posts:
    9
    First of all let me say I really love the cinemachine asset and hopefully someone knows a solution to my current issue. Also I´m a bloody cinemachine and unity beginner. I try to describe it as good as I possibly can, but since I purely work with bolt visual scripting I can barely provide any code, but I just need to understand the basic logic and if I do something wrong.

    So, basically:

    I have a main character with a free look camera. The camera follows the main character until the player decides to click an object. If he does I set the free look camera inactive and activate a virtual camera which I set to the position and rotation of the clicked object.

    If the player clicks another object, virtual camera 1 gets deactivated and virtual camera 2 gets activated, where I give it the position and rotation of the 2nd clicked object. (now if the continues to click objects, the 2 virtual cameras will only alter)

    My problem is the following:

    When I click an object the vcam position is set SOMETIMES 180° of my free look camera position or the 2nd vcam position. I believe this happens because the vcam remembers its original rotation and when set active it sometimes happens that it is 180° of the previous camera and thus does this strange 180° degree turn which looks like a barrel roll.


    upload_2020-9-13_14-36-15.png


    I tried this option with inherit position but that doesn´t solve it.

    It seems it doesn´t work from free look to vcam. From vcam to vcam I noticed an improvement.

    rotation.gif
    what happens in the gif
    1) camera rotates normally on player (fine). the wiggle is my mouse movement which is also fine for now
    2) I click an object (the black box with icons appear). The vcam is rotated the opposite side of the view point of my character camera, thus does a strange 180° rotation
    3) I remove the lock to the object, thus switching back to the free look camera. The transition is exactly as I would like to have it .. linear.

    I just want to know the following:

    When I set the vcam position and rotation, why is it on the opposite side of the object (so the furthest away from my character camera) instead of just having a linear transition where the vcam is the closest and shares the same view angle as my main character free look camera?

    I know that I do something wrong.

    Is there a way to give the vcams the view angle of the previous camera (so basically camera looks right, set vcam active and it also looks right)? or any way to make a real linear transition between 2 cameras (like force it?)

    Like, are there any options to modify the vcam frustum (the viewing angle of the camera) to be the same as the one of the previous camera? that would probably prevent the strange blend rotation that I get sometimes

    It seems like such a trivial thing to do and I just can´t wrap my head around it. ^^

    If anyone has a clue or hint what I could try it would be really appreciated.
     
    Last edited: Sep 13, 2020
  2. xyzwqmf

    xyzwqmf

    Joined:
    Jul 27, 2020
    Posts:
    9
    I solved my issue relatively by just testing a lot around. Seems like I have the best options with using 3 free look cameras instead of 1 free look and 2 vcams. The inherit position option seems to be strange between free look and vcams, at least for my situation.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    You should be able to get the InheritPosition to work properly with FreeLook -> vcam. Can you show inspectors for the vcams that weren't working for you?
     
  4. xyzwqmf

    xyzwqmf

    Joined:
    Jul 27, 2020
    Posts:
    9
    Sorry for the late reply, I didn´t check anymore after I got a result I was happy with.

    I can shortly show what I currently use since I have removed the vcam setup to freelook. I found that freelook transitions somewhat smoother then the vcams, at least after a lot of testing, but please note I´m an absolute beginner and I don´t use any scripting language but the visual coding solution "bolt", thus I try to explain it as good as possible.

    I have a main camera with the following brain:

    upload_2020-9-26_16-43-11.png

    it blends between freelook and freelook, where freelook 1 is my character camera, freelook 2 is the first object a player clicks and freelook3 is the 2nd object someone clicks. the 3rd object would then be freelook 2 again, so I use 2 freelook to transition between them. They both inherit the position of another freelook what in the end achieves what I needed.

    On runtime:
    upload_2020-9-26_16-45-37.png

    I enable and disable the cams based on the actions of the player.

    Freelook 1
    prio 11 due to being main camera of the player, rest has 10

    upload_2020-9-26_16-46-26.png

    freelook 2 on runtime after the player clicked an object
    upload_2020-9-26_16-47-50.png

    I set the the follow and look at and enable the freelook 2 and disable freelook 1, it then smoothly moves towards the clicked object, on disable it moves back.

    I had a strange issue where on transition from freelook 2 to freelook 3 if you click the same object twice, it would set both cameras 180° apart from each other creating a transition that ended in some kind of barrel roll.

    i solved that by forcing the position of the freelook 2 and 3 camera to be the same (forceCameraPosition).

    i´m kind of happy with the solution for now, the only minor thing left would be the transition from freelook 2 & 3 to the player freelook 1. if the inactive freelook 1 position is 180° of the other 2 freelooks, it creates a camera rotation where the cam looks on the ground and then to the player. It makes sense since it is the shortest transition it can make but it looks kind of strange. however, I see that as a minor thing for now.

    really love the cinemachine options and just wanted to leave my solution here and thank you :)

    i´m not sure its the perfect one, but it does its job very well for what I need ^^
     
  5. treetreenl

    treetreenl

    Joined:
    Jul 16, 2018
    Posts:
    1
    I'm actually having the same issue getting my freelook and virtual cam to transition nicely (matching position using inherit position). The issue is the transition going from my virtual cam to my free cam, where my free cam Y axis value resets to 0 upon swapping, which puts it into the ground, even though my virtual cam is shoulder height of my 3rd person character. Any ideas? These are the setups I have:

    See the camera jump to under the chracter here, when I have it set to "inherit position". Expected bahavior would be it taking the position of my virtual cam, or atleast closer to it than diving into the ground like now.


    Freecam part 1:

    Freecam part 2:

    Virtual cam:

    brain transition:
     
    Last edited: Dec 21, 2020
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Try Transposer instead of HardLockToTarget + CinemachineCameraOffset.

    So remove Cinemachine Camera Offset from your vcam. Change HardLockToTarget to Transposer (turn damping off) and set the Transposer's Follow Offset to (0, 1.13, -3.97).
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Also: there is an issue with FreeLook inheritPosition that sometimes results in the Y axis problem you describe. The workaround is to make sure that the FreeLook has the LookAt and Follow targets both set to the same point - without target offset. So if you're looking at the neck, make sure to really look at the neck (and not at the feet with an offset) and also follow the neck. If you also set the vcam to look at the same point, then you will minimize artifacts in the blending.