What are the uses of a Rect2?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By drumstickz64

According to godot docs:

Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

If it’s used for fast overlap tests, when should i use it over something like an area2d or a physics server intersect_shape call?

:bust_in_silhouette: Reply From: Inces

It is for simpler uses than collision testing. For example check if player is within screen rectangle. Check if enemy is within a square of distance from player. Check if unit is within borders of rectangle drawn by dragging mouse.

Oh so it’s for simple overlap testing.
One last thing is, if I had a large amount of square shapes that I wanted to detect overlapping for, would you recommend using PhysicsServer or Rect2?

drumstickz64 | 2021-11-04 23:26

I would use collision shapes, geometry or physics querries. Rect2 is only good for detecting single overlapping points with its has() method.

Inces | 2021-11-05 13:56