0 votes

For Example

var can_move = (true)

If canmove == (true):
(Input.is
actionjustpressed("ui_up"))

This dosent seem to input anything so do u always have to input actions manually

in Engine by (58 points)

1 Answer

+1 vote

Input.is_action_just_pressed() returns a boolean value (true/false), it "checks" for input and not used to "trigger" one.

Assuming you have a movement code when you press up:

 if Input.is_action_just_pressed("ui_up"):
    move()

You could simply do:

  if can_move:
     move()

Of course, if it is really important to simulate a keypress, then:

func simulate_up_key():
       var simulated_input = InputEvent()
       simulated_input.type = InputEvent.KEY
       simulated_input.scancode = 16777232#this number is scancode for UP
       get_tree().input_event(simulated_input)

https://docs.godotengine.org/en/3.0/classes/class_@globalscope.html

https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html

by (334 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 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 webmaster@godotengine.org with your username.