0 votes

Hello, I'm trying to have an area detection that performs different things depending on which shapes the player is overlapping with. I have an Area2D node with two rectangle collision shapes (one blue and the other green) which as I understand combine into one for the general detection. When I connect the signal, the overlap triggers as expected when the player enters any of the shapes, but after that I want to manually check with which shapes the player is colliding and here is where I am completely lost.

I'm using the Shape2D.collide() method but either I am confused with what it does (something about overlaps/collisions maybe?) or I am filling it with wrong info (transforms being the main suspect) because it shows really weird things like that the player is colliding with the blue shape while being only inside the green one.

Screenshot of the main scene and the areas


extends Area2D

onready var blueShape = $BlueShape
onready var greenShape = $GreenShape

func _ready():
    connect("body_entered", self, "on_body_overlap")

func on_body_overlap(body):
    var bodyCol = body.get_node("CollisionShape2D")
    var insideBlueShape = blueShape.shape.collide(self.transform, bodyCol.shape, body.transform)
    var insideGreenShape = greenShape.shape.collide(self.transform, bodyCol.shape, body.transform)

    print("--- Body overlap registered ---")
    print("Inside blue shape: " + str(insideBlueShape))
    print("Inside green shape: " + str(insideGreenShape))
    print("--- *** ---")

EDIT: Figured it out, it was the transform. I needed to check using the global one.

Godot version 3.3
in Engine by (12 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.