0 votes

So, I want an action to be performed when a kinematicBody2d enters an Area2d(the action is printing something), so I put a connection between these two bodies using the command "onArea2Dbodyentered" that can be found on the "Node" tab in area2d.

This is the code inside kinematicBody2d:

  func _on_Area2D_body_entered(body):
    print("Hello World")

In this case, "Hello World" is printed, but the problem is that it is printed without the kinematicBody2d and area2d having to contact each other... it just prints automatically when the game starts. How can I fix this and make it so that the output is only printed when the two bodies actually contact each other? Thanks in advance.

in Engine by (12 points)

1 Answer

0 votes

Are you manually calling this method from somewhere? What you want to do is select your Area2D node, then in the inspector on the right, select the Node tab, then select the event/signal you want (in this case probably body_entered), then click the Connect button at the bottom, and select the node you want to listen for that event, in this case it is the KinematicBody2D.

So I think the issue here is that you created the function for handling the signal/event, but you did not make the actual connection.

by (1,656 points)
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 Frequently asked questions and 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 [email protected] with your username.