This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

Godot version 3.5.1
in Engine by (12 points)

1 Answer

0 votes

Add a CollisionObject3D to the Ball and use its mouse_enter and mouse_exit signals:
https://docs.godotengine.org/en/stable/classes/class_collisionobject3d.html#class-collisionobject3d-method-mouse-enter

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):
        print("hit")

Note the use of intersect_point rather than a ray. More on raycasting: https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html

by (1,406 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.