- Home /
How to stop Camera from going into colliders
I've looked all over this amazing website for the answer, BUT I CAN'T FIGURE IT OUT! So, I've seen it worked for some people but not me. Here's what I'm using:
The DEFAULT ThirdPersonCamera from the ThirdPersonController which is the Construction guy that came with the older version of Unity. (like Unity 3. ._.) So putting the Near Clipping to like 0.1 didn't work. So I'm assuming it's the script. Which tell my Main Camera to go the axis it goes into... You know? Whether Mesh/etc. Colliders are in the way or not.
So here's the three script I have on my Camera:
Mouse Orbit var Target (Transform) //I already have my Game Object it wants to target in there var Distance : 5 var XSpeed : 250 Var YSpeed : 150 var YMin Limit : -20 var YMax Limit : 80
Smooth Follow var Target : (Transform) //Same as the first one var Distance : 10 var Height : 5 var Height Damping : 2 var Rotation Damping : 3
Smooth Look At var Target: (Transform) //Need I say more? var Damping : 6 var Smooth : Checked Box
What I want specifically is for the Camera to be similar to a legit OBJECT that can't go through walls with Colliders. Or ANYTHING with colliders.
Now BEFORE you insist I just get an Empty object that is a legit collider it's self and put the Camer aunder it, make it a child of the Empty Object, etc. I've already done that. I've even tried giving the collider the three needed scripts. And take them off the Camera. But it makes the collider go through the other colliders, is why I feel it's the script canceling out the collider.
Now I'd give you the script, but it's the default Unity Construction Worker scripts. So just find that and you have the script.
Any help? And sorry this is wordy. I just tried cancelling out all of the things I've tried to get specific answers.
Answer by Cherno · Apr 11, 2015 at 11:34 AM
Cast a ray from the camera target back towards the camera. If it hits anything, move the camera to the hit.point. Done.
I couldn't believe it was that simple, but it worked for me. Thank you so much!
Answer by rob5300 · Apr 11, 2015 at 11:17 AM
This is most likelly happening because the movement of the camera is not done via physics. I expect also the camera does not have a rigidbody eathier.
For this to work, you are going to have to eathier edit the script to make the camera move foward when it would go into an object to avoid it or make the camera movements happen via physics (like adding forces).
The Camera will require a rigidbody then, which you won't want using gravity ofcourse and it may need to be set as Is Kinematic, not sure.
Answer by vanjasretenovic123 · Feb 26, 2018 at 09:50 PM
U have to add Sphere Collider to Camera and to another objects if you didn't added. And you have to attach Rigid Body to Camera.