Hey someone knows what im doing wrong?

Godot Version

4.4

Question

im making a 3d game and im having a problem with the cursor

extends Area2D


@onready var normal: Sprite2D = $Normal
@onready var interact: Sprite2D = $Interact
@onready var combat: Sprite2D = $Combat

func _ready():
	 is_mouse_over["Enemy", "Interactable", "Player"] = false:
		set.Texture ("Normal")

func _on_mouse_entered() -> void:
	if_mouse_over[Enemy] = true:
		button.set_text("combat")
	if_mouse_over[Interactable] = true:
		button.set_text("interact")

func _on_mouse_exited() -> void:
	if_mouse_exited[Enemy] = true:
		button.set_text("normal")
	if_mouse_exited[Interact] = true:
		button.set_text("normal")

Please explain what your code is supposed to do, what it does instead, and what errors and warnings are provided to you (if any.) We (and people in general) cannot read your mind.

This doesn’t read like valid GDScript. Is this supposed to say:

if is_mouse_over["Enemy"] == true:

?

1 Like

the mouse is supposed to detect if its an enemy interactable or nothing by looking at the groups


when its over an specific group its supposed to change to a diferent texture just how the mouse changes on the pc if you are over text or something u can click

The code you have here seems unlikely to do what you want, or even build. Is it perhaps AI generated?

As it stands, your is_mouse_over is being addressed as if it were a Dictionary, though I don’t think what’s happening in _ready() is valid syntax even for that? But elsewhere you’re assigning boolean true values to keys defined by Enemy and Interact, except in one place it’s Interact and in another it’s Interactable…

I’m assuming this code is refusing to run, and there are warnings and errors.

Where is is_mouse_over defined? What does your scene hierarchy look like?

1 Like


is not ai im just very bad at this. and yeah it has errors

Fair enough.

Area2D is giving you mouse_entered and mouse_exited signals, but those only fire for the shape of the Area2D. You have three different children under it that you’re trying to differentiate.

What you probably want to do is get rid of the top-level Area2D and instead have three Area2D, one each for Normal, Interact, and Combat. Your hierarchy would perhaps look like:

cursor (Node2D)
    Normal (Area2D)
        Collider (CollisionShape2D)
        Image (Sprite2D)
    Interact (Area2D)
        Collider (CollisionShape2D)
        Image (Sprite2D)
    Combat (Area2D)
        Collider (CollisionShape2D)
        Image(Sprite2D)

Then you can simplify things:

# The "Combat" Area2D
extends Area2D

func _on_mouse_entered():
    button.text = "Combat"

func _on_mouse_exited():
    button.text = "Normal"
1 Like

i see and this will work for a 3d game?

It should? The mouse is on a 2D plane (the screen), “in front” of your 3D scene.

It really depends on what you’re trying to do, though. It seems like you’ve got a button and you want to set the label on that button to “Normal”, “Interact” or “Combat” based on which of three labels the mouse is over, but I suspect that’s not what you want the game to actually do.

I’m kind of guessing here, but it seems like you might be trying to make an RPG or a roguelike or something in 3D, and are hoping to make it so that (say) if the player mouses over a door or a chest, a “what clicking will do” label lights up with “Interact”, whereas if they mouse over an enemy it would light up with “Combat” and so forth.

If that’s what you’re hoping for, then you probably need to build things a bit differently. Give your 3D objects in the world Area3D collision nodes, and use a raycast. The magic phrase you want to search for would be “godot 3d mouse picking”.

If that’s not what you’re trying to do, if you could explain your game a bit it would be easier to help.

1 Like

its like the old resident evil games, the camera detects where you go and the camera moves accordingly. yeah but i want the mouse to change texture like in the old games not just a text that says something. i feel this makes it more interesting.

It sounds like what you need is 3D mouse picking plus potentially 2D “Area2D” stuff, and then logic that look decides relative priorities and picks a cursor shape.

The 2D stuff would probably be highest priority; if the cursor is over a 2D button (and therefore inside one of your Area2Ds), show the normal cursor or the cursor specific to that button. If the cursor isn’t over one of the GUI elements, use 3D picking to see if the mouse is over anything interesting in the scene, and then set the appropriate cursor based on that.

1 Like

i do have a ray casting on the camera in code.
i do not completly understand what u are saying

I’m assuming that you want to have some interactable UI on the screen as well. Buttons the player can click or something. I’m assuming that if (say) a chest is behind the button because of where the camera happens to be looking, you still want the mouse to use the “normal” cursor if it’s floating over the button, not the “interact” cursor for the chest hiding behind it.

1 Like

on that video i was testing the ui but yeah its interactable and you press tab to look at for example the health (arm).
so button is like a node or something?

There’s a whole pile of UI nodes called “Controls”. They give you buttons, text labels, layout controls, sliders, progress bars…

1 Like

yes, but like how do i connect it to another scene so that it detects the enemy. or make it detect the groups

Control and its descendants all have mouse enter/leave signals. You can put the gui in a separate branch of your scene hierarchy so it draws overtop.

so if i add the curosr scene as a child of lets say the map it would work?

Probably? You might have to fiddle with it a bit.