How can I detect a collision with a Polygon2D? I'm trying to make music fade in/out at certain regions of the game, so there will be a bunch of Polygon2Ds that designate the areas each track will play at.

I'm currently just checking each _process call for each polygon if the player is inside it with Geometry2D.is_pont_in_polygon(player.position, poly.polygon).
This is probably gonna be terrible for performance later on, but it's also kinda crappy to work with, because it completely disregards scale and position of the Polygon2D objects by getting the polygon points directly. This means I have to always make sure their positions and scales are 0,0 and 1,1, and manually move the actual points in the polygon to the right place. Sure, I could take poly.polygon and do some math to apply the polygon's position and scale on the points, but that would make performance even worse.

Just looking for simple collision detection between the player and the Polygon2Ds, accounting for position and scale as well. How can I do this?

  • xyz replied to this.
  • Dexie Use body_entered signal instead.

    Dexie Use Area2D node with CollisionPolygon2D or CollisionShape2D as a child. It can emit area_entered signal when other areas start colliding it.

      xyz ohhhhhhh I saw Area2D before but thought it was just for rectangular stuff. This looks interesting! Thanks.

      xyz Forgot to mention, the player is a CharacterBody2D. The area_entered doesn't seem to be firing, and I can't tell why. My current layout for the player scene is something like this:

      If I move the CollisionShape2D into its own Area2D so it can collide, there's a new warning symbol on PlayerCB (the CharacterBody2D object) saying it can't collide since it needs the collision shape.

      How can I make the shape apply to both the Area2D and also PlayerCB?

      • xyz replied to this.

        Dexie Use body_entered signal instead.