Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cinemachine Collider Problem

Discussion in 'Cinemachine' started by caixiang, Jun 27, 2017.

  1. caixiang

    caixiang

    Joined:
    Dec 2, 2016
    Posts:
    4
    I use Virtual Camera look at and follow a same target, then move target, Camera can move through wall(wall layer is default), Cinemachine Collider Against default layer.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    You need collider volumes on the walls. Do you have them?
     
  3. caixiang

    caixiang

    Joined:
    Dec 2, 2016
    Posts:
    4
    there is a Box Collider On the walls ,unity is 5.6.1, cinemachine is 2.0. I test it on edit, drag the target.
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    Yes I see the problem. You need to give the wall collider some thickness in Z. If things are too thin they will fool the Cinemachine collider.
     
  5. caixiang

    caixiang

    Joined:
    Dec 2, 2016
    Posts:
    4
    thanks very much,i will have a try.
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Amadeu likes this.
  7. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    I am having the same problem and have been googling. This is the only thread I found so I will continue here.

    I downloaded the sample project from above and have converted it to unity 2017 with cinemachine 2.0 installed for testing purposes. My actual project is in Unity 5.6 but behaves exactly the same way. To keep things simple I just want to get this sample project behaving correctly and use it to learn where I am going wrong. If I can make it work here I can figure out how to make it work in my current project. Since I am using the project already posted here and a google search for "cinemacine collider" returns this thread as one of its top 5 I thought it would be appropriate to just continue this thread as opposed to making a new one.

    My problem is the same as the original poster, no matter what I try the camera will go through walls. I have set the curb feelers extra long and managed brief collision but it seems to only be for the length of the feeler. At this point the camera collides and stays away from the wall until the tracked object moves closer to the wall by the distance of the curb feelers. I can check the line of sight box and it works perfectly. The camera will move toward the tracked object like it should but that's all it will do. A sideways collision only makes the camera move closer from the line of sight being occluded.

    Above it was stated that the thickness of the wall collider was too thin. I am probably missing something here due to my complete lack of knowledge and experience with unity. When I downloaded the project the wall was set up as a cube primitive with a box collider and a scale of 100,100,10. Is this too small to be detected by cinemachines collider? I have a feeling I am missing something else completely obvious here.

    I am using the project from above as an example. I imported it to Unity2017. I know this is the beta version but I am having the same trouble with Unity5.6 on a different larger project.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    Yes, you are right. I was too hasty in my previous answer about the collider bounds thickness on the wall. It's fine the way it is.

    Trying it again, I find that I get good results with these settings:

    upload_2017-7-1_16-33-40.png

    Video here:
    https://www.screencast.com/t/H9dAHxXF

    It's true that the Line of Sight feature seems to be doing all the work. I've logged an issue about the Curb Feelers not working adequately.

    Thanks for the post!
     
    ian22farrell likes this.
  9. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    Ok I may be completely misunderstanding the way a cinemachine collider component should work as I am very new to this. I thought the collider could function without the line of sight. I was imagining it working like typical collider on a rigidbody where it would aim to not penetrate a surface and just sit still at a fixed height or slide sideways as needed as opposed to just traveling closer to the target because line of sight was occluded. Line of sight would only kick in if something got between the camera and target which wouldn't happen if the target got closer to a wall only if something came between them without colliding first.
     
  10. xDavidLeon

    xDavidLeon

    Joined:
    Jun 9, 2014
    Posts:
    123
    I think I'm lost at something regarding the Cinemachine Collider behavior.

    I'm embedding a video with the issue: https://giphy.com/gifs/xT39CZCP9LklS1Tobu/fullscreen

    A very simple use case for the collider would be for the camera to not penetrate walls while keeping its orientation or pitch/yaw values. Right now, if I'm aiming to the right, the behavior of the Cinemachine collider forces the camera to aim up, and that's not the intended behavior for the obvious reasons.
     

    Attached Files:

  11. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    The collider is broken but they are working on it. The camera looks upward to preserve its lookat target wich I assume is the head. The line of sight moves the camera in and down because the collide part isn't doing anything.
     
  12. xDavidLeon

    xDavidLeon

    Joined:
    Jun 9, 2014
    Posts:
    123
    Thank you for your answer. Yeah, it's targeting the head, I guess I need to try and target a few meters in front of the player or something like that...? Well, I'll wait for the next version of the collider component.
     
  13. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    I have been using a clearshot group with 4 cameras low to high with the middle set to top priority. When ine looses view it switches to another. Using several positions like that I'm able to mimic a collision by moving the camera to the next available position. Its not as smooth as I would like but it works for now.
     
    Adam_Myhill likes this.
  14. pixelR

    pixelR

    Joined:
    Sep 16, 2013
    Posts:
    58
    I wanted to try and replace my 3rd party cam solution by Cinemachine today, but the collision feature just doesn't work at all (I do have colliders, layer set properly in settings, etc. - double checked everything). So I'd also be happy too see a quick fix for it. :)
     
  15. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    The collider will still work to an extent. The line of sight feature works great. If anything puts the look target out of sight the camera will follow a straight line from its desired offset toward the target until either the target is visible or it gets to the minimum target distance limit you set. The colider with curb feelers active and set to a reasonable length will push away from walls a bit but breaks down when the follow target pushes it farther into collision than the length of the feelers at which point it penetrates and line of sight takes over. The collision component will also trigger a change in a cloud camera system making the collided camera inactive while line of sight is broken from its desired offset. You can use several cloud cameras in close range to each other to almost mimic a standard collider. When one camera position collides it switches to one that hasn't. Not quite as smooth as just colliding because it has a finite number of positions to work with but when tweaked just right approximates it closely enough to at least be functional.

    Maybe we will get a hint at timeframe for the bug fix soon. I haven't heard anything but near future yet which is a pretty broad range of time. I do hear that Gregory is working on it and it sounded like it was pretty high on his priority list so hopefully we get word soon. Until then the cloud camera solution will have to suffice. I must say the rest of the cinemachine features have been excellent at least the ones I've used. It makes setting up camera fly through at the beginning of one of my levels super easy. Its a great tool and I'm glad Unity adopted it.
     
  16. pixelR

    pixelR

    Joined:
    Sep 16, 2013
    Posts:
    58
    OK, I see I have to be more precise, sorry for that. So: "but the collision feature just doesn't work at all *in my follow object cam setup*". I have time so I'd just wait for a fix instead of implementing workarounds, it's fine in my case. Otherwise yep, the tool is awesome, no doubt.
     
  17. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    Does the line of sight feature in the collider component working? Even with just one vcam set to follow and look at 1 target when the camera hits a wall it should zoom in on the target until its visible. I know its not exactly collision but it does preserve line of sight. I think we are looking for similar camera setups right now. I'm not using the workaround as a final product and wasn't suggesting you should use it as your solution. I should have been more clear. I have it set up this way for now because it was fairly easy maybe 10 minutes work and it has the camera working well enough for me to continue testing and work in other areas while Gregory works on his part. Makes it where I'm not really waiting and if they take a good bit of time fixing it I wont mind.
     
  18. pixelR

    pixelR

    Joined:
    Sep 16, 2013
    Posts:
    58
    Mea culpa. I have discovered what went wrong in my case (so it's not related to what others reported above, or so it seems for now during first tests). I had the follow target set, but Lookat not. As soon as I have set the Lookat property, the curb feelers and collision detection started to work. So my fault was to assume setting a follow target only would make it work.

    Edit: stopped working again, so my assumption about what's been wrong was... well, wrong. :)
     
    Last edited: Aug 6, 2017
  19. FrankenCreations

    FrankenCreations

    Joined:
    Jun 14, 2017
    Posts:
    326
    Yes. The colider does work to a usable extent. Its not quite right as you will probably find but still useful. As described above the curb feelers work some and line of sight works correctly. The only trouble I get at all is from the actual collision being able to get pushed through walls if line of sight isnt active. The curb feelers push off of the wall some but line of sight takes over too quickly. If you have a camera set at an offset of 3,3,0 when it collides it will not stay at a height of 3 instead it follows the line of sight path downwards toward the target. One the target is a distance of 1 from the wall the offset will be 1,1,0 instead of 1,3,0.
     
  20. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    It's been a couple of weeks coming, but the new collider is in CM 2.1, available now in beta. Please give it a try and let me know if it's working for you.
     
  21. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    166
    Hello, just a quick question related to this, how to avoid the "trigger" collision, in my project i'm using a lot of triggers, sadly every time the camera go through the triggers it starts to act like crazy, pointing everywhere till i get pass the trigger, then it comes back to normal behaviour... is there any way to disable the trigger collision? and by the way, changing the trigger layer doesnt work at all... I'm using unity 2017.1.1f1
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @deadlycrow You've set the triggers to be on one layer, and the "collide against" field on the collider to a different layer? And the triggers are being triggered by the collider? Is that what's happening?
     
  23. pleasantPretzel

    pleasantPretzel

    Joined:
    Jun 12, 2013
    Posts:
    34
    I installed the new CM 2.1. I've found that the CM Collider still ignores collisions if "Preserve Line of Sight" is unchecked.

    I am using the Collider with a FreeLook cam for a traditional 3rd person character setup.

    I'm certain all of the objects I'm referring to have collider components, and that in my CM Collider, my "Collide Against:" value is set to 'Everything'. The CM Collider script works as expected when "Preserve Line of Sight" is checked.

    Maybe I'm missing something or don't understand the approach? Curious if others are having similar issues.

    [[[ BTW - I just want to take a moment to express how amazing Cinemachine is and how exciting it is that my visions are no longer just dreams, I'm actually achieving them (easily and quickly!) thanks to Unity and you guys! I know that creating software/tools means you hear a lot about what *isn't* working from users, so I just want to thank you for the immense amount of stuff that IS working. thank you! :) ]]]
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @slufter So in the new collider implementation, there is only PreserveLineOfSight. If you think about it, an obstacle is just something that comes between the camera and its target, even if that obstacle is a wall you've just backed through. We've eliminated the distinction because, well, there isn't one. I think you'll find that PreserveLineOfSight, with the new algorithm, does the job.
     
  25. pleasantPretzel

    pleasantPretzel

    Joined:
    Jun 12, 2013
    Posts:
    34
    @Gregoryl Ah, I see. I've experimented with the settings and believe I've gotten the behavior I'd like. Thanks for response! I was a little caught up in misunderstanding semantics :)

    On another note, I found some strange behavior:
    Adjusting the Camera Radius in the CM Collider script leaves a collider at the origin of World Space. For example, in the inspector, I'll set the Camera Radius to something like 100 by accident, then back to 0 or a smaller number. The largest value entered for the Camera Radius persists (it seems), and it behaves just as a you'd expect a giant invisible collider to behave, interacting with all the rest of the game objects. Hope I explained that okay. Let me know if I need to re-explain. Not sure if there's something I've done wrong that caused this, or if it's a bug.

    EDIT: I'm using beta 2017.2.0b11 (osx10.9.5)
    EDIT2: Closing and reopening Unity removes the collider. I increased the Camera Radius again, and the problem reoccurred... and a Unity restart is necessary. Reloading the scene in the inspector without a Unity restart does not remove the collider.
     
    Last edited: Sep 22, 2017
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @slufter thanks for the report. We've located the culprit and should have a fix up later today.
     
  27. spokrock

    spokrock

    Joined:
    Oct 16, 2017
    Posts:
    8
    I’m using the current Cinemachine Collider and it works perfectly fine under iOS but fails under Andriod resulting in the camera passing through objects and all subsequent physics raycast to fail. If there is no camera collision then physics raycast in external scripts aren’t affected.

    If Cinemachine collision is removed external scripts also continue to process physics raycast.
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    Yes, this is a known issue and has been corrected. The fix will be in the next CM release. If you need a patch right now you can PM me.
     
    dynamer, BrandStone and ftejada like this.
  29. spokrock

    spokrock

    Joined:
    Oct 16, 2017
    Posts:
    8
    PM'ed my email address.
     
  30. DeCloudius

    DeCloudius

    Joined:
    Feb 23, 2018
    Posts:
    2
    my cinemachine collider looks different with all of you guys out there, i can't even find "preserve line of sight" and everything..
     
  31. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    What does it look like? Can you show a picture?
     
  32. lagruise

    lagruise

    Joined:
    Feb 23, 2017
    Posts:
    22
    My cinemachine collider is also lacking the "preserve line of sight" tick box. But the CM icon also looks different.
    I am on 2017.3, CM 2.1.10

    My issue is that I have the vcam body set to "tracked dolly" - where the track is almost on a circle around the player environment. For some reason the camera is moved to positions along the track where the player (look-at-target) is hidden behind objects instead of just staying still on position

    upload_2018-3-6_21-18-22.png
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @lagruise Yes the picture you show and the icon are the current versions. You must be comparing to old documentation or to tutorials made with older versions of CM.

    To enable obstacle avoidance, put a tick in the "Avoid Obstacles" tickbox.

    You can access the latest CM documentation via the Cinemachine/About menu item.
     
  34. lagruise

    lagruise

    Joined:
    Feb 23, 2017
    Posts:
    22

    Thanks
    I did try the "avoid obstacles" tick box but this stil forces the vcam to ride the dolly track half circle (to the opposite side of the original position) and then trying to manipulate its way into sight (acc to the selected strategy) instead of just staying in its original position. The hierarchy of logic appears that the nearest point on the dolly track has priority and then the vcam tries to avoid the obstacle. I would rather have it to evaluate effort to remove obstacle for each potential point on the dolly track. Especially since my camera is ortographic. Although I do manipulate the camera with a matrix4x4 as well - would this impact?
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    You are correct in your analysis. First the vcam is moved to the point on the Dolly track that's closest to the target, then it is adjusted to correct for any obstacles that occlude the target from that position.

    What you are asking for is entirely different, and not supported out of the box. The way to implement it would be to turn off the AutoDolly feature in the Tracked Dolly component, and implement your own algorithm to choose the best position on the track, according to whatever criteria you choose. Your script can set the vcam's position on the track by manipulating vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_PathPosition.
     
    Last edited: Mar 6, 2018
  36. lagruise

    lagruise

    Joined:
    Feb 23, 2017
    Posts:
    22
    Yes - that will be the way to go. Btw - is it possible to manipulate the speed with whch the vcam moves along the dolly track in the out-of-the-box setup?
     
  37. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    In fact there is no maximum speed setting. Maybe there should be. If you turn up the Z damping it will help. Of course your custom positioning algorithm can implement a max speed.

    Just a note about AutoDolly: because the algorithm is simply to choose the point on the track nearest to the target, it's dangerous to make a circular track around the playing area, unless you make it impossible for the players to move into the central area of the circle, where the closest point becomes highly volatile. As an extreme case to illustrate, in the exact center of the circle, all points on the track are equally close. Where should the camera go?
     
  38. lagruise

    lagruise

    Joined:
    Feb 23, 2017
    Posts:
    22
    Good point. What would you propose? Each scene I am planning for is essentially an environment built on a mountain/heap which is more or less cone shaped (wo the pointy edge). The player can traverse around the mountain/heap and my idea was that the camera would follow the player on tilt from above (ideally moving in a circular fashion around the mountain at the same distance from the mountain center - but varying height depending on where the player would be in the y axis). I came the conclusion that a dolly track (where i moved the dolly y position) would be good - but of course issues as you pointed out. But maybe there are other vcam options that are better suited?
     
  39. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    Your setup should work fine so long as you have an alternate strategy for the mountain peak. Maybe when the player is above a certain threshold you could just turn off the auto-dolly and push the camera up high enough to see the entire peak region without turning?
     
  40. lagruise

    lagruise

    Joined:
    Feb 23, 2017
    Posts:
    22
    For future use - My solution was actually to create two "dolly tracked" vcams associted to a half circle dolly track each. And then simply enabling/disabling the vcams (mutually exclusive) as the player passed through an invisible collider/trigger based wall (that separated the two halfs of the mountain/heap) . The transition between the two dolly tracked vcams are sufficiently smooth to give the impression of one coherent track motion - whilst I am rid of the dolly tracked proximity logic.

    Thanks for your kind support.
     
  41. dynamer

    dynamer

    Joined:
    Nov 22, 2017
    Posts:
    1
    hello I have the problem, can you send me the correct file?
    thank you
     
  42. mirkoemirbc

    mirkoemirbc

    Joined:
    Nov 17, 2016
    Posts:
    10
    Hello,
    I'm using cinemachine to follow my character from behind, but using Cinemachine Colliders I'm facing an issue that don't know how to solve at this point. In some points the camera stops showing objects in front of it. This happens when the camera is beside to a wall or an object with a thick collider.
    I'll upload a video to show you. I hope you can help me with it.
     
  43. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    You are using a very old version of Cinemachine. I suggest you upgrade, using the package manager. Before you do, be sure to delete the old Cinemachine asset from your project, otherwise you will have upgrade problems.
    (make a backup of your project first!)

    Current version of CM is 2.2.8.
     
  44. mirkoemirbc

    mirkoemirbc

    Joined:
    Nov 17, 2016
    Posts:
    10
    I though so ... :(
    Thank you very much.
     
  45. RR_Daphne

    RR_Daphne

    Joined:
    Jan 29, 2019
    Posts:
    1
    Hi, Ive been Googling for hours and can not figure out how to get the cinemachine collider to recognize the LookAt target I assigned at the start. I apologize if this is a dumb question but, is there another way we assign the LookAt target? I also put the same target in all three rig's lookat overrides to no effect. cinemachine Lookat mystery.png
     
  46. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    This is a bug in the UX. The warning is incorrect, Collider will in fact recognize the LookAt target set in the FreeLook.
     
  47. emmadamain

    emmadamain

    Joined:
    Jun 16, 2019
    Posts:
    1
    still at a fixed height or slide sideways as needed as opposed to just traveling closer to the target because line of sight was occluded.
     
  48. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    ?
     
  49. cvadiablo

    cvadiablo

    Joined:
    Jun 2, 2017
    Posts:
    19
    upload_2019-7-20_18-5-55.png

    Can't find the "Line of Sight" option in Cinemachine Collider... why?
    2019.1.8f1
    Cinemachine 2.3.4
     
  50. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    Renamed to "Avoid Obstacles"