- Home /
How can I tell the user can see an object, from any angle?
Hello all, Please check the image bellow. It is a big cube made of little colored cubes (gameObjetcs). The cubes for each color have its Tag. The user can rotate the big cube at will, viewing it from any angle. How can I tell the user could see the Red Cubes? If we rotate the big cube 180 degrees the red cubes would face the opposite direction and it will not be visible to user at that moment. But the user could see the red cubes if he rotates the big cube. As the game goes on, the little cubes are destroyed. I need to calculate when the user could not see the red cubes, no matter how he rotates the big cube. In this situation, the red cubes would be completely covered by other cubes. How do I do that? Calculate if the red cube could or could not be seen from any angle? Any help will be greatly appreciated Thanks
Answer by tanoshimi · Jul 12, 2014 at 06:20 AM
Try performing a raycast from the camera to the red cube (perhaps, for more accuracy you could perform several raycasts to each corner of the cube). If the red cube is the first gameobject that the ray hits then it is visible.
Note: Don't be misled by the renderer.isVisible property - although it sounds like this could be used to test the visibility of an object, it really only tests whether it is inside a camera frustrum (and therefore sent to the GPU to be rendered), not whether it is visible to a player.
Hi tanoshimi, I´ll try that and post the results here. Thank you
Hi tanoshimi, How can I calculate the raycast direction using the red cubes position? I have to do that to try a hit on the red cube, right? Thanks,
It works! To calculate the direcction for the raycast I have to do (target.position - origin.position). Thanks a lot.
Your answer
Follow this Question
Related Questions
How to get where my camera borders a plane 1 Answer
Obstacle avoidance 1 Answer
C# RayCast Fire Cooldown DeltaTime Help 1 Answer