I want to know if the object is visible in the camera view and if it can see, then how much screen space occupied by the object as a percentage
If the problem can not be solved in this way, then that’s my goal:
I want to get the Transform component of object with a specific tag (eg tag Apple) if it takes a lot of space on the screen, for example 25%
Ok, for the percentage you will first need to collect quite a bit of info. 1. Is the camera perspective/orthographic 2. Field of view (perspective) or size (orthographic) 3. Is the camera viewport full view 1W and 1H 4. Distance the object is from the camera 5. The size of the object 6. Size of the screen Once you have all of those you will then be able to programmatically determine the area percentage. If you fill me in with some of the info above I can help you out with the formula.
1) Camera Perspective 2) Field Of View 20 (can change) 3) Viewport rect x:0, y:0, W:1, H:1 4) Distance the object is from the camera = 27 5) Object size 1.5 (Default Cube Scale) 6) 800*480 (can change)
Question 2: … I will need more information, please view my comments, momentarily.
Ok, I’ve created a test scene with some example and an output label of percent of screen left. You should be able to derive from the script and example everything you need.[19292-determineviewarea.zip|19292]
I want to raise an event if the object on the screen is big enough.
If you know the object, and you know the size and its all static (unchanging) just determine whether its in view and the distance from the camera and based on what you know you can just set it to be true without going through all the trouble of being exact.
Who do not understand, that is the meaning. Need to formalize the target rectangle and subtract the area of the screen and the rectangle of the target. Then calculate the percentage
Ok, for the percentage you will first need to collect quite a bit of info. 1. Is the camera perspective/orthographic 2. Field of view (perspective) or size (orthographic) 3. Is the camera viewport full view 1W and 1H 4. Distance the object is from the camera 5. The size of the object 6. Size of the screen Once you have all of those you will then be able to programmatically determine the area percentage. If you fill me in with some of the info above I can help you out with the formula.
– MFen1) Camera Perspective 2) Field Of View 20 (can change) 3) Viewport rect x:0, y:0, W:1, H:1 4) Distance the object is from the camera = 27 5) Object size 1.5 (Default Cube Scale) 6) 800*480 (can change)
– PanCrucian