How to connect _on_area_2d_mouse_entered/-exited to script that is attached to Node3D

Godot Version

godot-4

Question

Hi! I really hope I’m putting this in the right section on here , I’ve been struggling with an issue and can’t find a way to fix it or a specific tutorial and I’m a beginner at anything surrounding code.

First off I want to say what the problem is, I want to make a 3D model rotate via mouse input in a 2D menu but only if the mouse enters an Area2D/CollisionShape2D I’ve set up in the UI I’m making

I found a good tutorial on how to make an object rotate with mouse input and that script is on that Node3D, the model spins exactly how I want it to in the UI but the mouse input is being registered anywhere I click

I’ve been trying to somehow set up the Area2D signals in the script attached to the Node3D but don’t even know how exactly to approach it and make it so that the rotating only works in the designated rectangle of the CollisionShape2D.

Any help is immensely appreciated, I’ve been trying to do this myself for 3 hours but I’m not experienced enough with how the engine works in some areas and also don’t possess the coding skills to be able to come up with a solution.

How about this:

  • add a boolean global variable in_area_2d to the script
  • set it accordingly in the two entered/exited functions
  • in your _process function, adjust the 3D object only if the new variable is true.
1 Like

thanks a lot! I’ll try to do that and see if I can do it

Hi! I tried doing this but it’s always not processing and I’m not sure what I did wrong
I hope I didn’t misunderstand what you suggested

Your two conditionals in_process are identical?!
What should happen if in_area_2d is false?

OH it’s not possible to do it this way? sorry about that :smiling_face_with_tear: as mentioned I’m not really experienced with any coding, been only doing it for about a month.

I want it to stop the process if the mouse is not inside the Area2D so I thought making it “not is_processing())” and then somehow restarting the process again with the 2nd if statement would work

I did play around with it in various ways before and putting the “set_process([…]))” in the functions outside of _process but that only enabled and disabled _process if I entered and exited the Area2D collision rectangle instead of it only being enabled if the mouse is inside the CollisionShape2D