P
P
Pragma Games2022-03-11 15:00:44
Unity
Pragma Games, 2022-03-11 15:00:44

How to determine if a point falls within the camera's field of view?

Hello. I have objects in my scene that can emit particles. But the player does not always see them. I would like to optimize this process and not show the particles when the player does not see them. The OnBecameVisible and OnBecameInvisible methods are not suitable, since they are tied to the mesh renderer of the object, and for particles it turns on when the particle starts and turns off after the end of the work. The GeometryUtility.TestPlanesAABB method is also not suitable, since a disabled particle does not have a collider. What can you advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2022-03-11
@PragmaGames

Anything that doesn't get into the camera won't be rendered.
You can turn off the generation with a simple check:
(But it will be seen that the particles just appear from the source at the moment they hit the camera)

Vector3 screenPoint = Camera. main. WorldToViewportPoint(_pooledGameObjects[i]. transform. position);
bool onScreen = screenPoint. x > 0 && screenPoint. x < 1 && screenPoint. y > 0 && screenPoint. y < 1;
particles.SetActive(onScreen);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question