Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Official Camera / Cinematics

Discussion in 'Open Projects' started by cirocontinisio, Feb 3, 2021.

  1. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Basecamp for all things camera and cinematics. Questions and discussion about how we are / will use Timeline belong here too.
     
  2. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    itsLevi0sa likes this.
  3. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    I would like to work on this. I was thinking of creating a prefab with a trigger collider which we can place wherever we need a camera change. it would have a reference to virtual camera and an event it will raise with the camera depending on which side the player exits the collider on. the camera manager would listen for the event and raise the priority of the camera passed in the event and blend to it.

    this should not have any issue on entering and exiting quickly as if we exit on the same side we won't raise the event.

    I was thinking of using a box collider trigger and restrict the player from entering and exit only from opposite faces using the level design. if the player enters/exits from the side for any reason the code would treat it as entering / exiting from the opposite face he is closest to.

    please feel free to mention any suggestions or potential issues.
     
    cirocontinisio likes this.
  4. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    All sounds pretty good.

    I think regarding sides, it all boils down to camera design. For instance:
    If you want the camera to follow the player from behind as it goes through the trunk, the VirtualCamera associated to that volume needs to be on the right side. If it's on the other side, it will start tracking the player from the front, preceding it. And also we might get a weird blend, or the camera going through geometry.

    So... will the script be able to handle composite colliders? (made of multiple colliders) Will it register multiple OnTriggerEnter? (which could cause issues - or not!)
    Things to keep in mind!

    I've made a drawing:

    CinemachineCameraSwitch.gif

    You see how as the player is going out of the trunk, if it immediately goes right, the camera which is trailing behind will go through the geometry.

    So yeah, just things to keep in mind as you work on it. Feel free to give it a shot, maybe make a demo scene and put it in the folder
    /Scenes/Examples
    with all of its assets inside there.
     
  5. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    Update:
    I have opened a PR: https://github.com/UnityTechnologies/open-project-1/pull/365. You can test it using the scene: Scenes/Examples/CameraSwapTest. I have tried to recreate your scenario in that scene.

    I found that if I enable the cinemachine collider on the freelook camera it seems to handle most cases of going through objects. Also as far as I tested the multiple triggers issue did not arise.

    can you think of any other scenario I should try out?

    one more thing: Where should I document the prefab? I have made a couple of assumptions that a level designer who is using the prefab may need to know about, like the player should enter and exit long the local z axis of the prefab
     
  6. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Thanks, I left a few comments.

    What do you mean "enable": our Freelook should already have it on.

    Generally we put docs on the wiki. . And to submit documentation, you can just one an issue, since you't make a PR on the wiki.
     
  7. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    Yes it's already enabled but it had all layers set to transparent.
    upload_2021-2-14_8-45-46.png

    so It wasn't actually trying to avoid anything.
    I have set it to nothing for now only in my scene
     

    Attached Files:

  8. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    Also regarding compound colliders, they have issues with triggers. The parent even with rigid body will not treat them as a single trigger, so we will have multiple ontriggerenters and exits, one for each child collider.

    EDIT: after looking further into the docs this seems to be the case for all collision callbacks with compound colliders. I will see if I can come up with a scenario where this might cause a problem.
     
    Last edited: Feb 14, 2021
  9. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Check again. Transparent Layers is set to Everything, but Collide Against is set to Occluding Objects and Tree Leaves (and Default by mistake I think, we should remove that probably).

    There's two types of collision and thus layer filtering: the camera trying to stay out of objects (= Collide Against), and the line of sight (= not Transparent Layers). This allows us to have the character hidden behind objects (where we use the stencyl shader) but the camera view not clipping through them.
     
  10. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    I have updated my PR according to your suggestions. The camera will now be swapped when the player enters/exits the volume of the collider. Also I have changed the system to use Compound colliders. All colliders should be added as children of the parent gameobject of the prefab.

    Please review it when you can.

    The only thing I haven't changed is this: https://github.com/UnityTechnologies/open-project-1/pull/365#discussion_r575700060. Could you please clarify whether I should put a script on the individual virtual cameras to set them up.
     
  11. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
  12. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    I have made all the requested changes.
    please review the PR when you can.:)
     
    cirocontinisio likes this.
  13. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Provided some feedback again!

    Ah, one more thing: try not to touch the Addressable Assets config file. This time it merges fine, but it might create conflicts.
     
    vjs22334 likes this.
  14. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    I agree with your first point I'll implement it.

    Regarding your 2nd point about using an int on the parent to keep track of collisions, that is what I did initially but when I put a rigidbody on the parent, the pig chef was always triggering ontrigger events twice. the capsule collider and character controller each seem to trigger it. while this won't be a problem as it will increment and decrement twice. I thought using child collider scripts and booleans is more robust in terms of avoiding this kind of issues. what do you think?
     
  15. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Hmm. I don't think it becomes more robust, at the end of the day they are the same algorithm: "put all the colliders you detect in a list, and check if the list is empty to swap the camera".

    But let me take another look in the editor before confirming!
     
  16. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    well the boolean system deals with duplicate calls to onenters and onexits from the same trigger which may cause the counting method to fail. But it kinda forces the parent - child system as other wise the parent does not know which collider( trigger) was hit. unlike onCollision events we can't get a reference to both colliders through the collision object in ontrigger events.
    If we could somehow do that we can get rid of the children.
     
  17. vjs22334

    vjs22334

    Joined:
    Oct 11, 2018
    Posts:
    11
    I think I found a better way to resolve the Issue we had of needing "two cameras running on the same track". Since we had a child trigger system already. I thought maybe we could choose the camera based on which child trigger was entered. So I added a camera field to the child trigger which is the camera which will be used if that child is entered. if that field is empty the parent's.
    camera will be used instead. I feel this system gives a lot of customization options. we can even add a field for which camera to swap to on exiting a trigger in future if required. Let me know what you think.

    Ps: I'm not sure How to fix that one merge conflict with the camera system prefab. could you take a look
     
    Last edited: Mar 22, 2021
  18. JoaoSantos

    JoaoSantos

    Joined:
    Mar 31, 2014
    Posts:
    20
    Hey folks. I feeling the camera movement to fast to control. I think we can reduce the speed, what you thing?

    With that, we reduce the labyrinthitis and nausea when we move the camera in combat, for example.

    I made a test with a value. I can make a PR, if it's not a problem.
     
  19. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    742
    Did you just tweak the number? I think the issue is somewhere else, I think we did something wrong and the code is not framerate-independent, because it feels good sometimes and not some other times.
    I think I noticed it feels way too fast when the game is built, which is when it's running faster. So it's probably that.

    Did you look in that direction? Time.deltaTime and making it framerate-independent?
     
unityunity