#help with mouse pass through for a Desktop pet game
1 messages · Page 1 of 1 (latest)
Just enabling them is not enough. You have to define what part of the screen is and isn't passtrough
I recently saw a plugin for Godot mono that had improved clicktrough support. But is only for Windows afaik since the implementation would have to vary per platform.
It could be that you are scaling up the polygon a lot. Was that intentional? In updated_array.appen(vec * 3 + animated_sprite.global_position) the vec * 3 basically scales it up 3 times the size/position.
So, the polygon is at the origin and what you want to do is to move it to the centre of the window, which means, instead of adding animated_sprite.global_position (which feels like the logical thing to do 🙈) you want to add something like Vector2(256,256) if your window is 512x512 - so that the polygon is at the centre of the window from origin (which is at the top left corner of the window).
Interestingly enough on windows, everything outside the polygon is clipped according to the docs, but not so on Mac and Linux.
Hope this helps 🌸
These are just visual polygons, are you using these points for the passtrough ones?
ah, k
I don't think it matters where the polygon is located (in the hierarchy or in terms of the Node,s position), because I'm assuming the vertices of the polygon are always in local space and when the engine draws it, it is just relative to the Node's origin. So when you move the Node, yes the polygon moves, but when you use the polygon data, you are just getting data relative to the local origin (0,0).
What I would suggest is to multiply and scale to the size of your animated sprite and then add the centre point (width/2, height/2) of the window you are trying to apply it to.
var updated_array = PackedVector2Array()
for vec in collision_polygon_2d.polygon:
var v = vec * 0.5 + Vector2(256,256)
updated_array.append(v)
get_window().mouse_passthrough_polygon = updated_array
The above assuming your AnimatedSprite is scaled at 0.5x0.5 and your window size is 512x512
I just realised that your game is full screen and you are essentially only moving your character 🤦 - where as I was moving my window while dragging the sprite and my game was never full screen 😅
There is more.. 🫠 hold on
extends Sprite2D
var dragging = false
var of = Vector2(0, 0)
@onready var collision_polygon_2d: CollisionPolygon2D = $Area2D/CollisionPolygon2D
func _ready() -> void:
get_window().transparent_bg = false
func _process(delta: float) -> void:
if dragging:
global_position = get_global_mouse_position() + of
var updated_array = PackedVector2Array()
for vec in collision_polygon_2d.polygon:
var pos = (get_viewport().canvas_transform * global_position)
updated_array.append(vec + pos)
get_window().mouse_passthrough_polygon = updated_array
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event.is_action_pressed("click"):
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
of = global_position - get_global_mouse_position()
dragging = true
elif event.is_action_released("click"):
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
dragging = false
func _draw() -> void:
draw_polyline(collision_polygon_2d.polygon, Color.AQUA)
I typed in a lot and it all disappeared 🤷 so I will keep this short now.
You'll have to multiply the position of your character with get_viewport().canvas_transform to get the position of the character on screen - which is where you want to move your polygon to. Also you'll have to do it every frame unlike the way you are doing it right now in _ready. I would also recommend setting the window to borderless and fullscreen/maximised than manually setting the size like how you are doing.
This is what I did 😅
You can also technically drag your character out side of the screen, especially if you have two monitors. In case of a window, you would be dragging the window across to the other screen. Unless your game is positioned and resized to stretch across all screens 😅 So many choices 😅 All the best.