|
Hi, 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,
(comments are locked)
|
|
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. Thank you for the link of the script! I was looking for this for days!
Apr 07 '12 at 07:39 PM
PotatoOrgyLt
The mouse orbit improved did not work for me. It was very jittery, like going back and forth between different positions rapidly.
Dec 01 '12 at 12:26 AM
create3dgames
(comments are locked)
|
|
have i got an awesome prefab for you:-
(comments are locked)
|
|
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;
(comments are locked)
|
