Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | julkip |
I am programming a small AI for a multiplayer game so that it can be played in single player mode. For this I want to generate the inputs a human player would do via code, so that I don’t have to reprogram the player2 scene. The code looks a bit like this:
onready var input = InputEventAction.new()
func _process(delta):
input.pressed = false
if (player2_needs_to_move_left):
input.action = "PLAYER2_LEFT"
input.pressed = true
elif (player2_needs_to_move_right):
input.action = "PLAYER2_RIGHT"
input.pressed = true
Input.parse_input_event(input)
This works fine, until the player has to change directions. For example if player2 starts to move to the left and then needs to move to the right, the PLAYER2_LEFT action keeps beeing pressed and additionaly PLAYER2_RIGHT is also being pressed.
How can I get the code to “release” the input, once it is done