- Home /
Reduce size of plane frustrum in code
That probably didn't make sense. Let me explain. I'm using this code gem:
public static bool IsVisibleFrom(this Renderer renderer, Camera camera)
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
return GeometryUtility.TestPlanesAABB(planes, renderer.bounds);
}
which I found in the forums to determine whether something is in the camera view. Now, I want to make it so that it only detects things inside a slightly smaller frustrum, so things at the very edge of the screen aren't included. How can I reduce the size of this frustrum while maintaining the use of this code?
As a hack, you could change the field of view of the camera just before the call and restore it after. Note if this is a 2D game there are simpler alternatives.
Any reason you cant do it in the editor? what are you trying to accomplish here?
I'm not trying to reduce the actual size of the camera's view (i.e. field of view), but rather the size of the frustrum that the code above uses, so that objects at the very edge of the screen are not contained in it.
Well.. if you really want a quick way, you could always place a box collider parented to the player, with on trigger checked, then code on collsion enter/exit stuff that detects other colliders within it. So, that would be smaller than frustrum planes, since it doesnt spread out of distance, just goes straight out, since, it can only be rectangular in shape.
Answer by thef1chesser · Oct 24, 2013 at 08:20 AM
My attempt would be something like this
Bounds b = new Bounds(Vector3.Zero, Vector3(xsize, ysize, 1));
return GeometryUtility.TestPlanesAABB(planes, b);
Your answer
Follow this Question
Related Questions
How can I know if a gameObject is 'seen' by a particular camera? 11 Answers
Planar reflection is getting cut off when using camera with an oblique viewing frustrum 0 Answers
How to get a ParticleSystem to play when you can't see it's origin point. 0 Answers
Only show GameObject if at least 1 pixel is rendered 0 Answers