0 votes

I'm wondering if there's an easy way to get sort of a percent of how visible an object is in the 2D viewport.

in Engine by (33 points)

1 Answer

0 votes

There are Rect2 functions: https://docs.godotengine.org/en/stable/classes/class_rect2.html

Use intersection (clip()) of object and viewport rectangle. Then use area of this intersection and area of object.

var visibility_rate : float = 0.0 # 0..1, multiply by 100 for "percentage"
if intersection_area > 0.0:
    visibility_rate = intersection_area / object_area
by (1,636 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.