Preventing camera from passing through walls

I have tested putting colliders on the Main Camera, the CinemachineVirtualCamera as well as colliders and rigidbodies on the walls. I still cannot prevent the camera from passing through a wall.

I have not worked much with Cinemachine, so not sure if I might be missing something.

I have completed the course, and learned a ton of information. Thanks. I’m going through now and adding/updating the assets to match the type of game I’m shooting (no pun intended) for.

Here’s my settings for a CinemachineCollider added to the virtual camera.
I made all the walls on an Obstacle layer. This causes the setup to react if there is an obstacle between the camera and the selected unit.
The Preserve Camera Distance strategy makes the camera move up to avoid the wall when it’s in the way. The other option is Preserve Camera height, which will try to move the camera THROUGH the wall until it’s not in the way. This isn’t always wanted, especially if the character is right up against the wall on the other side.

image

4 Likes

Thanks. I had looked for this collider previously, but could not find it (thinking it was a ‘component’). It is actually an ‘extension’ that is added from the CinemachineVirtualCamera section. I’ll play around with the settings and see what I can achieve. Thanks again for your thought process.

1 Like

Yeah, it’s a bit strange how it’s implemented. It’s data stored in the VirtualCinemachine, not as a component on the GameObject, but the display tricks you into thinking it’s a component.

2 Likes

I may have to try a different approach. I tried using the cinemachine collider, but the camera still passes through the walls. Thanks again for your ideas.

Well, nothing I try seems to keep the camera from passing through walls (or around them). I tried the Cinemachine Collider as well as the Confiner…neither worked. I believe the reason is because the control is from the CameraController game object, not the cinemachine camera itself. The confiner option kept the camera within a designated area, but the CameraController kept moving (which in turn, turns the camera). Thanks again for any advise.

1 Like

The CinemachineCollider should be the only thing you need, it should prevent the camera from having objects in front.
Do you have the LookAt field correctly assigned? Are you sure you added the CinemachineCollider to the right VirtualCamera? Should be on the main one, not the Action Virtual Camera
Did you set up the correct collider layer? On both the objects and the CinemachineCollider?

Perhaps the issue is because the camera target object is touching the floor, maybe lift it up by a tiny amount .1f on the Y

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms