# Camera Collison with scene objects

I think this is more of a 3D math question over programming.

I have a Kinematic Ridgidbody Main camera with a .03m sphere collider that is free roaming, looking around various large scene objects while mesh colliders. Currently i can see collisions, as all my OnCollisionEnter/Stay/Exit all throw debug logs. However i want to keep the camera from passing through the object and even bounce back a bit on the angle of reflection from the camera's angle of movement and the collision point's normal reality to the collision point. (I might have to settle with the angle of incidence from the camera itself if mesh object's geometry is too complex.

As you can see with the code below I've been trying different things, and at low speeds, the camera bounces off the object at various angles given the mesh collider's state. I want to prevent pass-through of the object by the camera indefinitely.

``````void OnCollisionEnter(Collision info) {
Debug.Log("Collision!");
cameraRigidbody.isKinematic = false;

Vector3 norm;
norm = Vector3.Cross(info.impactForceSum.normalized);

}
void OnCollisionStay(Collision info){
Debug.Log("Colliding!");
//cameraSpeed = 0;
Vector3 norm;
norm = Vector3.Cross((info.contacts[0]).point, transform.position);
info.contacts[
//int bounceDistance = 1;
//Vector3 bouncedPosition = transform.position + (bounceDistance * norm);
//flyToPosition = bouncedPosition;
Debug.Log("Still Colliding!");
}

void OnCollisionExit(Collision info){
Debug.Log("Done Colliding!");
//cameraSpeed = settings.CameraSpeed / 500f;
}

``````

The reason the camera can pass through other objects is that it's kinematic. You could try changing it to a non-kinematic rigidbody and moving it by applying forces to it, but that could be a bit tricky to get right.

A simpler option would be to keep the camera kinematic and use a combination of raycasting and Physics.CheckSphere. Before moving the camera, raycast to the point you want to move to and make sure you won't be colliding with anything. You can also use Physics.CheckSphere to determine if there is enough space at the destination for your camera's collider sphere to reside without touching other colliders.