Deleted

Hello!
I thought bounds = new Bounds(new Vector3(120, 0, 120), new Vector3(240,240,240)); will make a box centered at 120,0,120 and its size will be 240,240,240

so its extents will be 0 to 240 on x, -120 to 120 on y, 0 to 240 on z

This definitely isnt the case though, am I looking at this wrong?

For X axis
When my player is at 0,0,0, the grass is drawn
When my player is at 120,0,0, the grass is drawn

When my player is at -1,0,0, the grass isnt drawn
When my player is at 121,0,0, the grass isnt drawn

For Y axis
When my player is at 0,0,0, the grass is drawn
When my player is at 0,240,0, the grass is drawn

When my player is at 0,-1,0, the grass isnt drawn
When my player is at 0,241,0, the grass isnt drawn

No mater where my player is at on z axis, as long as he is within the x and y, it will always be drawn. So if player is at 0,0,4000 the grass gets drawn

This makes absolutely zero sense to me

Well, what makes you think that this is not the case? The Bounds constructor literally looks like this. Your definition of “extent” may be a bit misleading in this context since “extent” in the bounds class is just half the size. So it’s essentially how far it extents in either direction from the center. See the definition of the min / max properties and you will see what I mean.

ps: If you’re exploring the Bounds struct and wondering where some of the methods are defined, note that most types in Unity are declared as partial. This is to seperate native code binding from the pure managed part. The native binding for the Bounds struct is in the Math.bindings.cs. So methods like IntersectRayAABB are defined in native C++ code in the engine itself.

You edited your question and added some details about rendering. This wasn’t mentioned at all in the first version^^. The Bounds struct is just a data struct. Similar to a Vector3 or a Color struct. It’s not really clear where you use or set the bounds or where / how this bounds is used specifically. Note that a Bounds value always represents an AABB (axis aligned bounding box). However just like any spatial quantity it’s not strictly related to a certain coordinate space. For example Renderer.bounds returns the worldspace bounding box that encloses the rotated bounds of the mesh. In contrast Mesh.bounds defines the AABB of the mesh in the mesh’s local space.

The way Renderer.bounds work when the object is rotated is like that (let me dig up one of my old drawings):
7510286--925937--Mesh.bounds.png

So Mesh.bounds defines the AABB in localspace of the mesh, the space the vertices are defined in. Renderer.bounds returns the AABB of the enclosing AABB in worldspace. Of course, if the object isn’t rotated, the two bounds would match.

Note the way frustum culling works has nothing to do with the objects position, especially not your player object (whatever that might be). Frustum culling of the camera works by checking which renderer.bounds intersect with the frustum of the camera. Note that ALL cameras count, that includes the sceneview camera. So if you do some fancy custom culling, you can not “see” the culling in progress as you would be watching that part with a camera in order to see it ^^. Though still unclear what this is actually about.

ps: If you want to see the culling happening, try to temporarily making the bounds smaller. In that case when the bounding box leaves the camera frustum (in case only one camera is actually viewing the object), you would see the object disappear too early since the mesh is larger than it’s bounding box. However when the bounds is setup correctly, you should never “see” the object disappearing. That would be kind of against its purpose ^^.

Are you sure that’s the condition you want to check? Doesn’t look like that makes much sense to me ^^. Why do so many people construct a new Vector3 out of transform.position? And to me it looks like you messed that up ^^.

Just to avoid confusion, you used your players x coordinate for both, x and y and your z coordinate is actually your players y coordinate. This seems really odd, especially considering that you have different dimensions for x and y in your bounds.

if you actually want to test your players position agains your bounds, you should just do

if (bounds.Contains(player.transform.position))
1 Like

:slight_smile: No problem. Glad we sorted this out ^^. Such mistakes happens to everyone once in a while. Have fun!