This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I mapped the names of my four custom actions as strings with vector2 values for the four directions.

var dir = {"left":Vector2(-1, 0), "right":Vector2(1, 0), "up":Vector2(0, -1), "down":Vector2(0, 1)}

How can i now react on anything pressed and output the matching action to put it into a variable to do this (the variable, i want to store that, is key)?

    if step == 0:
        old_pos = position
        direction = dir[key]

    if grid.is_valid_move(pos, direction) || step > 0:
        move = true
        step += 1
        pos += STEP * direction

        if step == 144:
            move = false
            step = 0
            pos = Vector2(round(pos.x), round(pos.y))

    position = pos

        direction = Vector2(0, 0)
Godot version v3.4.3
in Engine by (75 points)
edited by

For detecting inputs, have you looked at the _unhandled_input() or _input() functions?

1 Answer

0 votes

In the _physics_process(delta) function you can put

if Input.is_action_pressed("action"):

Or one of the many other is_action functions that are under Input. It's pretty much up to you. Happy coding.

by (144 points)

i thaught maybe there is a solution, that i donĀ“t have to use such lines fou rach direction.
i thaught about a single line, that returns me, wich action is pressed, as a string variable, that i can use to take the correct content from the directions-dictionary-variable

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.