Trouble with detecting collision in the same frame to make smart labels
Hello everyone.
I am having a hard time making “smart labels” for my game so that the user can view the points of interest (POI) with ease.
I’m going to explain some things before getting to the problem:
Contextualization
Billboard
The point of interest is a gameObject with a Canvas with its Render Mode set to World Space. Its role is simply to display the image and name of the space below it. Basically it is a billboard that constantly looks at the camera. It is also a way in which the user can interact with the world, so I added a box collider to it, making it able to detect a ray-cast to then perform some action.
Scenario
It consists of a 3D city and the camera is top down in its standard mode but it can be tilted up to 60 degrees for perspective immersion.
Smart Label Logic
What I did was to set a specific relevance to each point of interest. Then I created a prefab that is placed exactly in the position of the POI. They are responsible for calculating the collisions, that is why they contain a Mesh renderer (which is for visualization only. I choose this instead of Gizmos so I could see them work within the game tab), Rigidbody and Sphere collider to be able to compute the collisions.
When the game starts, I organize the list with the labels by relevance, so that it can be placed in order.
Now, when the user zooms in or out, I resize the Sphere’s and make them collide in order to see which POI’s need to be displayed. As the user zooms out, the sphere’s grow bigger and only the important one’s will show and vice versa.
The ideal situation
When zoom changes:
Deactivate all the spheres Colliders
Resize all spheres Colliders
Activate the game objects that contain the spheres (the Colliders are disabled so that they wont collide!)
Activate the game objects that contain the spheres ONE BY ONE in the order of the already sorted list
If it collides, deactivate the current (It means it collided with one of higher relevance)
If it doesn’t collide, activate it.
Problem
When physics is involved, it wont compute the collision until the next frame. So, if I add this to the update function, it would not get the collisions correctly due to the frame-rate. If I add it to a coroutine and add the sphere, tell it to wait to the next frame and so on, IT WORKS, but takes too long to complete, making it unusable.
I feel like i’ve tried everything… I tried changing to fixed update, using OnTriggerEnter and even Check-sphere. NONE of these have worked.
I really need a direction because I have run out of things to try.
Your answer
Follow this Question
Related Questions
Compatible collision constraint methods 0 Answers
Stop objects from going through eachother? 0 Answers
Is there any good sample code for shooting a projectile and collision detection? 0 Answers
Detecting collision altho disabled on matrix. Help!! :'( 0 Answers
OnTriggerEnter not being called 2 Answers