how do i make it so when i hold down right click the item will move toward the mouse?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By whywhyw

i knew the answer to my question but i forgot it so thats why im asking.

:bust_in_silhouette: Reply From: ramazan
func _input(event):
  if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT:
	  if event.pressed:
		  print("kkkk")

///////////// follow
https://forum.godotengine.org/40507/solved-enemy-follow-player

:bust_in_silhouette: Reply From: skysphr

You can either use _input() and change states between following and non-following or directly call Input.is_mouse_button_pressed() inside _physics_process().

First way

var following: bool
func _ready():
    following = false

func _input(event):
    if event is InputEventMouseButton and and event.button_index == BUTTON_RIGHT:
        following = event.pressed

func _physics_process(delta):
    if following:
        position += get_local_mouse_position().normalized() * follow_speed * delta

Second way

func _physics_process(delta):
    if Input.is_mouse_button_pressed(BUTTON_RIGHT):
        position += get_local_mouse_position().normalized() * follow_speed * delta

(untested code but it should work)