mouse_entered for PhysicsBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By calvar

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.

:bust_in_silhouette: Reply From: johnygames

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.

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 mouse_entered 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 mouse_entered for them? Is it used in a different way?

calvar | 2019-12-29 21:25

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.

johnygames | 2019-12-29 22:21

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

calvar | 2019-12-29 22:25

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

johnygames | 2019-12-29 23:02