Character Body-Area2d collision detection outside overlapping

Godot Version

Godot_v4.2.2-stable_win64

Question

Hello! I am quite new to Godot and I have an issue with Area2D collision detection. Basically, What I want is when a player overlaps that tree, the tree becomes transparent, like in Stardew Valley. The mechanics works but I also get collision when the body of player is not overlapping the tree Area2D (first GIF) and also there is weird behaviour while overlapping (second GIF). This problem is intermittent, meaning it’s not always happening:

areaDetectionBug

areaDetectionBug2
tree
tree_overlapping_gd


character

I actually found the solution. Please close this topic with status resolved. I cannot do it.

Hi there!

It would be awesome if you can share how you solved this, so that people searching for the same problem will find a solution.

Once you did that, feel free to click this icon on your own answer to mark it as the solution:

image

I had the player scene set on Autoload because I wanted to use it in Tree scene. Thus, I had another instance of player, behind the world tiles and I couldn’t see it. This instance was also interacting with tree’s area2Ds and consequently the behaviour in my topic.

In order to get the player characterbody2D in the tree scene I used Area2D.get_overlapping_bodies() method

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.