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)