+2 votes

Hi!
So, there is this thing when you can use input(event) to get single signal of (pressed)&(released) inputs,, but what if i want to make that as an input for movement?
Can you connect "func" between multiple "func" or call a variable, get a signal that an input was pressed in "input(event) " and then execute it in "fixed_process(delta)"?
I hope this doesnt sound too confusing~

in Engine by (227 points)

2 Answers

+1 vote

Yes, sometimes you need to do things that way to get more control over input events and not just for movement.

One way, managing variables on _input (always with set_process_input and set_fixed_process true):

var movement = Vector2()

func _input(event):
 if event.type == InputEvent.KEY && !event.is_echo():
    if event.is_action_pressed("left"):
        movement.x = -1
    elif event.is_action_released("left"):
        movement.x = 0

func _fixed_process(delta):
  move(speed*movement*delta)

Another, clearing variables on process:

var movement = Vector2()

func _input(event):
 if event.type == InputEvent.KEY:
    if event.is_action_pressed("left"):
        movement.x = -1

func _fixed_process(delta):
  move(speed*movement*delta)
  movement.x = 0

What works better depends on the game, like, grid based movement may get better result with the second, doing extra position checks before clearing the movement variable and ignoring input event while moving.

by (7,934 points)
0 votes

Not entirely clear on what you're saying. But you can also actively poll for input using the Input singleton at anytime during process loops.

Such as:

extends Node2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    # or actions: Input.is_action_just_pressed("ui_up")
    if(Input.is_key_pressed(KEY_UP)):  
        print("UP is being pressed.")
by (5,274 points)

problem with this one is that action is pressed "delta" times.. what i meant is that it checks was it presed in input func (once)
func input(event):
if event.is
action_pressed(.......
and when its pressed (one time) then somehow affect fixed process func that executes delta times per second u know..

Sadly, the is_action_just_* was not added to the 2.1.1 (has some problems).

But there are ways to do it with just Input too (from simple flags to more complex structures), search in the Q&A, there are many answers to that if it is what you are looking for.

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.