Item appear on mouse hover

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

Hello, I’m a beginner so please explain in detail and simple steps if possible!
I’m working in 3.5 in the 3D Space.

I have a rigidbody item called Ball and then a spatial node which is a UI, as a child of Ball that gives me the name of it on a rectangular nameplate. Currently the nameplate is hovering over the ball item. I want the nameplate to only be visible when the user’s mouse is on it, how do I get this to work?

I tried using Area node and mouse_entered but that wasn’t working, and was recommended to use a raycast. I’m struggling with implementing the raycast.

:bust_in_silhouette: Reply From: spaceyjase

Add a CollisionObject3D to the Ball and use its mouse_enter and mouse_exit signals:

You could use a raycast here but godot is already doing the work for you with collisions. An alternative may look something like:

func _physics_process(delta):
    var space_state = get_world_3d().direct_space_state
    # Get the mouse position
    var mousePos = get_global_mouse_position()
    # Check if there is a collision at the mouse position
    if space.intersect_point(mousePos, 1):

Note the use of intersect_point rather than a ray. More on raycasting: Ray-casting — Godot Engine (stable) documentation in English