I am trying to understand camera collision in Unity but their is one thing that I can't seem to solve:
When I turn my camera against a gameObject like a cube or other primitive, the collision isn't detected.
I tried almost everything like linking a collidable object to a camera, adding a mesh collider or rigid body to it but the camera stays on going through walls when I turn with it.
Any idea's how to solve this?
Thanks in advance,
asked Nov 28 '09 at 03:45 PM
To make something collideable you need to attach a collider to it and a rigidbody if it should be moving in the game.
Although cameras aren't usually collidable since the scripts moving them will most likely don't use the physics engine.
What script are you using to move the camera?
[Edit] Aha, mouse orbit, well the mouse orbit script does change the position of the camera every frame regardless of the physics, so you won't be able to have a camera with that script which responds to collisions, to avoid making the camera go through objects you can use a modified mouse orbit script which can be found on the wiki: http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitImproved It will look for it there is a wall between the target and the camera and if so, shorten the distance to the target to make you get a clear view.
make sure gravity is off, and also make sure that you freeze rotation, also.. its going to push through walls unless you place all that code inside a FixedUpdate, at least these are the things I did to improve mine.. however it still snaps a little, but not related to the camera.. related to the pivot its fallowing;
answered May 18 '12 at 06:09 AM