but the coordinates are completely different than expected. x is negative to the right instead of positive and the numbers are affected by zooming in and out.
but again the coordinates are completely different from what the bar at the top shows me.
If there’s any way to convert these coordinates to match what they are on the ruler guides on the top and left, that would be amazing or perhaps I’m just going about it completely wrong. I don’t know. Any help would be appreciated.
Messed around myself for a bit, i unfortunately couldn’t get anything either. Sorry this one’s a toughy. Hopefully someone here can help, signaling assistance squad
Viewport.global_canvas_transformorigin gives you the top-left corner of the canvas (where the red and green lines cross) so it will have negative x when you scroll the canvas to the left and changing the zoom will change the position of the top-left corner of the canvas
@tool
extends Node
func _process(delta: float) -> void:
var vp = EditorInterface.get_editor_viewport_2d()
var transform = vp.global_canvas_transform
var center = transform.affine_inverse() * (vp.size / 2.0)
$Sprite2D.global_position = center