I have a camz variable that is controlled by the MouseZ function. It affects how far from the PlayerController the camera is.
camz = MouseZ();
PositionEntity (camera,Vec3(0,0,camz);
To initiate camera collisions, I position a second pivot about 0.2m from the pivot used to rotate the camera. This means that my raycast won't be affected by the mesh.
pivot2 = CreatePivot(pivot);
PositionEntity(pivot2,Vec3(0.0f,0.0f,0.2f));
PointEntity(pivot2,camera)
Then I do a EntityPick command from that second pivot to the camera. If there is a collition, I put a third pivot at the point of the collision. If camz is less than the distance to that 3rd pivot, I ignore the collision. Otherwise, the camz variable is overridden by the collision.
if (EntityPick(&raycast,pivot2,10.0f,1)) {
PositionEntity(pivot3,Vec3(raycast.X,raycast.Y,raycast.Z));
PositionEntity(camera, Vec3(0,0,Min(camz, EntityDistance(controller,pivot3)-1.0f)));
}
else {
PositionEntity(camera, Vec3(0,0,camz));
}