#How do I get the mouse position for Input.warp_mouse and Input.parse_input_event?

25 messages · Page 1 of 1 (latest)

balmy talon
#

How do I get the mouse position out of a control's global_position property to use in Input.warp_mouse and Input.parse_input_event?

I have tried varies things like...

  • position
  • global_position
  • get_local_mouse_position()
  • get_global_mouse_position()
  • get_global_transform_with_canvas().origin

All seems to have their own problems.
I am using Godot 4.1

quaint niche
#

get_viewport().get_mouse_position()

#

relative to the viewport

balmy talon
#

nope that doesn't work

quaint niche
#

get_window().get_mouse_position() relative to the window

balmy talon
#

that just lerps my mouse to top left corner

#

ok just a sec

quaint niche
#

there's so many things tbh

balmy talon
#

nope still not it

quaint niche
#

is the origin for the control the top left of the viewport

balmy talon
#

no

#

I was using sprite anyways to debug it

quaint niche
#

well the origin for warp_mouse is topleft of the window, so, you need to find where the origin of the control node is relative to the active window

#

which it really should be top left

balmy talon
#

it basicly is

#

I was running the scene not the game

#

I can use position and then it's in the right direction but it's not scaled with the window

#

it's still 128x128 instead of 128x128*4

#

I can get it working with get_viewport().warp_mouse() but then there is no way to parse input

balmy talon
#

I still need this

#

this doesn't work in godot 4.0

#
func click()->void:
    var evt = InputEventMouseButton.new()
    evt.button_index = MOUSE_BUTTON_LEFT
    evt.position = get_viewport().get_mouse_position()
    evt.pressed = true
    Input.parse_input_event(evt)
    evt.pressed = false
    Input.parse_input_event(evt) ```
#

let alone trying to get the position of the node2d

#

the position it returns is not in the correct space