0 votes

I would like for a PhysicsBody2D to pront something when the mouse pointer enters the CollisionShape2D associated with it. This works correctly for Area2D by connecting the mouse_entered signal. However, when I try it with any PhysicsBody2D it does not work. I am working on ubuntu linux and Godot is installed through steam. Any help would be appreciated.

Greetings.

in Engine by (25 points)

1 Answer

+1 vote

Edit: Both Area2D and KinematicBody2D inherit from CollisionObject2D and they are both capable of detecting input events. The difference is that Area2D has the Pickable setting enabled by default, whereas the KinematicBody2D doesn't. All you have to do is enable it. Go to the Inspector panel and enable "Pickable" under the corresponding setting. You could also do this programmatically by calling input_pickable = true.

by (1,887 points)
edited by

Thank you for the answer. Yeah, sorry for the incomplete info., it is godot 3.1.

I am connecting the signal using a function like:

func _on_KinematicBody2D_mouse_entered():
   print("mouse entered KinematicBody2D")

Its true there are no PhysicsBody2D objects, but all of the classes inheriting from it (Kinematic, Rigid or StatyicBody2D) seem to have the same problem, unless mouseentered is not suppose to work in the same maner as for Area2D. I could add an Area2D child to the PhysicsBody2D classes but, what is then the purpose of the mouseentered for them? Is it used in a different way?

I figured it out! They both inherit from CollisionObject2D and they are both capable of detecting input events. The difference is that Area2D has the Pickable setting enabled by default, whereas the KinematicBody2D doesn't. All you have to do is enable it. Go to the Inspector panel and enable "Pickable" under the corresponding setting. You could also do this programmatically by calling input_pickable = true.

I will update my answer to include this info.

Great!! Thank you! I would have never figured that out.

Glad I helped! Please upvote and mark this answer as best so that others can find it useful too.

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.