- Edited
Hi all,
New to posting here, but have been playing around with Godot for a while and have been using the knowledge and help here and elsewhere with a lot of gratitude. This time, I ran into something I can't seem to find help for. Not sure if I'm doing something wrong, if there's a bug I stumbled upon or if I'm just missing some basic stuff. Any help is appreciated.
I'm working on a top down 2D game with hoverable/clickable KinematicsBody2D's. The mouse_entered() signal works as expected, but on a moving sprite the mouse_exited() signal only fires as soon as the mouse is moved. It makes sense to some degree, but it is not what I'd logically expect to happen in a game. Say I'm hovering over a character, not moving my mouse, and the character wanders off... it's still 'hovered' in my code, and can still be selected by a mouse click.
I feel I am missing a fundamental step in the process, because I can't be the first running into this. I made a simple test scene and the behaviour is the same. KinematicsBody2D is set to pickable, belongs to a layer and there are no controls blocking mouse events. It responds to mouse signals... just not upon moving away from under the mouse cursor.
Only workaround I can think of myself is to trigger a mouse move signal myself (I saw Input.parse_input_event, that might do the trick), but somethig tells me there should be a better way (like no workaround at all).
Any ideas?
Easily reproduced by a single scene with a KinematicsBody2D as root, Sprite and CollisionShape2D as children:
extends KinematicBody2D
var path = [Vector2(100, 100), Vector2(200, 100)]
var step = 0
var velocity := Vector2.ZERO
func _ready():
pass
func _physics_process(delta):
var dist = position.distance_to(path[step])
if dist > 1:
velocity = path[step] - position
move_and_slide(velocity)
else:
step = (step + 1) % 2
func _on_KinematicsBody2D_mouse_entered():
print('mouse entered')
func _on_KinematicsBody2D_mouse_exited():
print('mouse exited')