0 votes

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

Godot version 3.4.2
in Engine by (14 points)

2 Answers

0 votes
func _input(event):
  if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT:
      if event.pressed:
          print("kkkk")

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

by (755 points)
0 votes

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)

by (1,305 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.