0 votes

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

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 PLAYER2LEFT action keeps beeing pressed and additionaly PLAYER2RIGHT is also being pressed.

How can I get the code to "release" the input, once it is done

in Engine by (47 points)

Please log in or register to answer this question.

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.