Remove out of View objects to reduce physics simulation

Hello everyone,

I want to remove the entities outside of the camera to reduce physics simulations and physics time. Currently I am using trigger planes while basically are enabling and disabling the entities based on the player’s position.

I want to disable the entities which go behind the player.

Link to game: https://playcanv.as/p/5Pp07I7b/

PS: I have read the topic where Will suggests to use the frustum containsSphere against a bounding sphere,but I cannot have that many individual bounding sphere to test. So, I would want to know if any other solution exists or if anyone can suggest me a better solution then the existing one.

Thanks

Each entity can check it’s position relative to the camera and if it is off the bottom of the screen, disable itself. You can also disable any entities that fall off the platform.

So are you saying, get position of every object at run time and do some vector math to calculate its relative position to the camera and disable or enable it? isn’t this inefficient since we are getting positions of objects continuously and doing some calculations?

I would check the relative z distance to either the player or the camera (so a subtraction and an if statement. If they are both under the same parent, then you can use localPosition to avoid the extra calculations needed for getting worldPosition). It’s no less efficient than any other method.

How about just put a trigger collider behind the camera?
Capture

Its working, but is it the most efficient way?

Hard to tell as I don’t know how Ammo tracks objects in the world (IE is it segmented or is it tracking every possible object that isn’t asleep).

1 Like