0 votes

Hello I'm creating a farming system for my game. I have a StaticBody2D with a CollisionShape2D acting as the crop, it detects if the mouse is hovering it . When I hover my mouse over the node it fires the mouse entered/exited signal without issue, but lets say I keep my mouse still and move my player, the camera will shift with the player but if the mouse happens to hover over any another crop node after the camera shift it doesn't fire the mouse enter/exited signal unless I move the mouse. Is there a simple way to fix this behavior or should I try to intersect the position of the mouse whenever the player gets close to the crop to verify it is hovering it?

Godot version 3.4.4
in Engine by (21 points)
edited by

Just for clarification: the mouse enter/exit signals work as intended. But when the player node is in that position, the signals don't function as intended? So you're trying to find a way to have the spot consume the mouse input without the player node consuming it?

Yes the signals work as intended

Forgive me for the crude edits, the red dot would be the mouse
picture 1

if I move the mouse on top a the potato object the enter/exit signal works as intended
picture 2
if I leave the mouse on the same position and only move the player to the right side even though the mouse is on top of another potato that potato object doesn't fire its enter/exit signal, if I stayed on the same position while only moving the mouse between both nodes, both would fire their signals.

picture 3

I still don't quite understand your problem. Do you want to move the player character over some object and have the mouse detect the object? The thing is, the StaticBody2D will detect the mouse cursor entering and exiting the collision. If the mouse cursor isn't moved (i.e. no motion), no mouse-related signals are emitted. When the player character moves, any body collisions that are set up by the StaticBody2D can detect the character.

What I want is to detect when a motionless mouse happens to hover a object as a result of a player movement.
I have a area2D to check if the player is within the interaction range I might just use that with the physics process to intersect the mouse position while the player is within that range.

2 Answers

+1 vote

Are you saying that as a result of moving your character, the view scrolls but the mouse position hasn't changed and is now hovering over a different "crop" ? If this is the case, I have conducted a few tests and haven't encountered your error. What type of collision shapes are you using for the StaticBody2D ? I tried my tests on a Windows system with a rectangle "collider" and positioned several "crops" in sequence and caused a scroll while keeping the mouse motionless and everything worked as expected.

by (141 points)

Yes, this is the exact scenario. Moving my player scrolls the camera while keeping my mouse in the same position, the crop node doesn't recognize the mouse being on top of it. I'm also using rectangle shapes for my collider.

enter image description here
The Hurtbox, PlayerDectectionZone and the StaticBody2D are all in different layers as well. The BuildingAreaBounds is only present while the player is trying to place the crop, afterwards it is removed.
All the signals are connected to the "Plant" Node2D

I also tested it with a StaticBody2D with a rectangle collision and pickable enable, I had the same results
enter image description here

In my tests, I had the mouse "signals" tied to the StaticBody2D and it worked fine and not a Node2D. Are you sure the layer values you are using aren't conflicting with something else on that layer(s) ?

That's my guess as well, it's probably another area interfering with the mouse tracking. I did a workaround earlier. Made it so when the player enters the interaction area, I check if the mouse's position in the TileMap matches the tile the crop is on and if yes I make my variable which tracks the mouse become "True"

When I did my tests, I made sure that the StaticBody2D was on a completely separate layer to everything else and I ensured that the colliders for each weren't overlapping each other or anything. The other possibility is that the signals attached to your "HurtBox" and "PlayerDetectionZone" are absorbing the mouse signals. An easy way to test this is to simply move your StaticBody2D node further up the tree (you can use CTRL+UP when the node is selected to do this) so that it receives signals before anything else in that tree.

I turned off monitorable and monitoring for all the Area2D's my player has along with disabling their collision shapes. I just attempted to do what you said and I still get the same result.

For good measure I made a entire new project, the player is on layer 1 and the object I want to detect my mouse is on layer 2. I added a simple movement script for the player and attached a camera so the view can scroll once the player moves. For the object I turned on pickable and gave the object a rectangle collision shape along with the godot icon as a sprite. (Red would be the object)
enter image description here
I still got the same results, I tried swapping the order of the Sprite and the CollisionShape2D just in case. Could this be some sort of hardware issue? My current machine is a laptop. I'm using a mouse but I couldn't be bothered to turn off the touchpad, if it matters the screen of the laptop happens to have touchscreen too.

It doesn't matter about the order in the scene for your test project because only one thing receives signals (which should be the StaticBody2D). Mine is essentially the same setup with the script on the StaticBody2D as follows:

extends StaticBody2D

func _ready():
pass # Replace with function body.

func onStaticBody2Dmouseentered():
OS.setwindowtitle ("Mouse Entered: " + name)

func onStaticBody2Dmouseexited():
OS.setwindowtitle ("Mouse Exited: " + name)

Ensure that the StaticBody2D is the one receiving the mouse signal information and not some other node. Scroll around with the mouse positioned as required and you should see the window title text change as the mouse enters/exits the collision area as a result of scrolling.

Sadly even following your instructions it still doesn't work, I believe it might be some sort of hardware issue. I can verify that once I get back from holiday and run the project on my PC.

0 votes

If the mouse cursor does not move play casino slots online for real money the signals associated with the mouse are not emitted. When the player character is moving, any body collisions that are configured by the character can be detected.

by (14 points)
edited by

In this case I'll just make the physics process constantly check if the mouse intersects the node while the player is within a certain range.

PS: I think you might have added the wrong link there LOL

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.