Yo, I’m new, what can I do to move the player by moving the mouse? Here’s what I have so far, I used the code from the Mouse and input document page
Keep in mind, this is a 2D Game
var x
var y
func _input(event):
# Mouse in viewport coordinates.
if event is InputEventMouseButton:
print("Mouse Click/Unclick at: ", event.position)
elif event is InputEventMouseMotion:
print("Mouse Motion at: ", event.position)
x = event.relative.x
y = event.relative.y
# Print the size of the viewport.
print("Viewport Resolution is: ", get_viewport().get_visible_rect().size)
Okay, are you trying to move it by the movement of the mouse or by the clicking of the mouse? If its by clicking, do you know how to use the input map?
if you want your player to move to the mouse position when mouse is clicked. send the mouse position to player when mouse click, let player calculate the direction to move by (mouse_pos - self.pos).normalize() (this is pesudo code) and move in that direction until mouse_pos is reached.
if you want your player to “follow“ your mouse, do the samething but the input event is now InputEventMouseMotion. I dont understand why you are using event.relative here.