How to get x position of mouse

Godot Version 4.3

trying to find only the X position of the mouse click, so that then I can have my character move_toward it.

Try this, the easiest way:

var click_pos := Vector2.ZERO

func _physics_process(delta):
   if Input.is_action_just_pressed("mouse_left"):
      click_pos = get_local_mouse_position()

   #Use here the click_pos.x as the x position of mouse

But first, define the mouse_left input map in the project settings.

1 Like

Ah that makes perfect sense, I was using global position, thank you.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.