Topic was automatically imported from the old Question2Answer platform.
Asked By
Repertix
I don’t know if this a bug or something but since today, an Area2D that I use so the character can interact with anything depending on the direction he’s watching has been working weirdly. Today, I just made little changes that don’t affect this Area2D. So here’s the thing, when I want to interact with something it doesn’t work. After testing with prints, I found out that the Area2D detects body_entered and then body_exited instantly after the first one, even does when the body stills on the Area2D collision shape making it unable to interact with it. Is this some bug or I need to check my code?
Edit: Forgot to mention that sometimes that I start the game it works has planned to do and other times does what I mentioned.
Definitely going to need more information haha. wanna show your script for the Area2D’s interaction?
This has only happened to me when I have freed nodes from within an Area2D and it emits the body_exited signal.
scrubswithnosleeves | 2021-02-12 04:49
The Area2D has not coded. But the player does about this and is basically this:
var object = null
func _body_entered(body):
if body.has_method("interact"):
object = body
func _body_exited(body):
if body.has_method("interact"):
object = null
The situation where I encountered this problem was when my Area2D’s collisionshape was overlapping my KinematicBody2D’s collisionshape and they were on the same Physics Layer and Mask. Thus, on initialization, Area2D’s body entered/exited is triggered. But in your case, I’m not entirely sure.
Which should tell you which body is being detected.
Using prints and if statements to see what’s happening, I can confirm what is happening, when the Area2D enters the CollisionShape2D, the Area2D detects body_entered and instantly body_exiting with the body the no exiting really. I used if statements so the object will not be null until the exiting body is the same as the stored object, so yeah, I think is a bug or something.
Edit: Found out what happened, in the connect function I put “body_entered” instead of “body_exiting”, but that’s not all, I didn’t modify that line since a lot of time ago, so It’s weird that the Area2D worked as intended until now.