Camera Colliders and Resets

Hi,

In my level, I’ve got a narrow corridor the character needs to walk through. Now, the way the camera follow script is setup, when the character turns, the camera moves and moves to such a distance that it goes through my walls.

I want it to hit the wall and stop otherwise controlling the character gets disorienting. Now, I’ve tried two ways so far and neither have worked so I figured I’d see if anyone else has done this before.

First I just added a sphere collider to the camera itself, but that did nothing. Then I created a sphere with collider, added the smooth follow script to it. Took the follow script off the camera and then made the camera a child of the sphere.

All that happened then was the sphere just went through the walls too… :frowning:


Also, I'm trying to figure out how to create a "camera reset" button so when you move a character 180 degrees, rather than waiting for the camera to rotate round, you can just click a button and instantly reset it.

I'm also considering making actual camera controls so you can use, say, the "U,H,J,K" keys to rotate the camera manually, on top of the automated follow script, though I don't know if that would be too complicated.

Mike

Just some thoughts:

It sounds like you are using the transform to move the camera as opposed to physics. Have you tried using OnCollision…() in you camera move script to check if you are in contact with the wall. If you are, then move your camera differently. You will have to play with it a little since you will still need to follow your character. Perhaps cast a line from the character to where the camera should go then if you get a collision point position your camera at that point.

For the camera reset, set the camera’s position to the spot it should be when the button is pressed.

To add the camera controls, add the input in the Input Manager and give them a name. Model them after the “Horizontal” and “Vertical” inputs. Then in your script where you are currently getting the input, probably by querying “Vertical” and “Horizontal”, put in the new names you gave your input in the Input Manager.