Godot Version
v4.3.stable.official.77dcf97d8 (Linux Mint 22.1)
Question
Hi
There is a polygon collision 2d component in my project. This component is reshaped every frame via code according to the area scanned by the mouse. Plus (0, 0) to form a complete triangle. (So when my mouse is at coordinates 5-15 in the first frame and 20-50 in the second frame, the shape of the polygon in the second frame is like this: (5, 15), (20, 50), (0, 0))
In this way, I try to detect whether the mouse is touching anything between two frames, even with fast movements. The idea is not pretty bad, but in practice, Signals cause some weird problems.
Normally when I enter and exit the obstacle with my mouse cursor the signal should be triggered but most of the time it is not. After some long long experiments I noticed that if I keep the mouse cursor still on the obstacle the signal is triggered every few seconds. I couldn’t notice a pattern but that’s all I know.
extends Area2D
var pos : Vector2
var pos_prev : Vector2
func _process(delta: float) -> void:
pos = get_global_mouse_position()
%CollisionPolygon2D.polygon[0] = Vector2(0, 0)
%CollisionPolygon2D.polygon[1] = pos
%CollisionPolygon2D.polygon[2] = pos_prev
pos_prev = pos
func _on_area_entered(area: Area2D) -> void:
print("Collided!")
I’ve been working on this problem for a day and tried every solution I could find regarding Area2D and Collisions but can’t get a logical result.