Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | T Lang | |
Old Version | Published before Godot 3 was released. |
I’m trying to make button-controls for my character.
The character is a KinematicBody2d and moved using the _fixed_process(delta)
.
Everything works as expected when using input_map and mapping keys, and using is_action_pressed
, but when trying to programatically create an action, it does not work.
I want to add a button, so when clicked, it fires the same action as the key-input.
In the button:
func _on_RightButton_pressed():
var ev = InputEvent()
ev.type = InputEvent.ACTION
ev.set_as_action("move_right", true)
get_tree().input_event(ev)
I can see the action in the _input
-function of my character, but the _fixed_process
does not catch the action.
From my character:
func _fixed_process(delta):
if Input.is_action_pressed("move_right"):
print("Move Right")
func _input(event):
if not event.is_echo() && event.is_pressed():
if event.is_action("move_right"):
print("Move Right")
So…what is the difference between an action set using Input Map (prints “Move Right” from both _fixed_process
and _input
) and explicit defining an action in code (only prints “Move Right” from _input
)
What is it I’m not understanding here?
From other examples I’ve seen that some move their character directly in the _input-function, and that would solve my problem, but still I don’t get the difference between setting an action in Input Map and using a script.