Show a textbox and stop the main character

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pancotto

Hi everybody!

I am trying to make a “Castlevania II - Simon’s Quest” type of game.

After studying some tutorials I have managed to organize the base of the game.
Now I am facing this problem:
the main character pushes a crate and reveals a door, then a message (a label attached to the character) appears asking the player if he wants to enter by pushing the UP button.
Normally the player wouldn’t be able to move the character and only be able to push that single button.
Right now, instead, I can move the character and the label which is rather comic…
How could I “freeze” the character?

Hope my question is clear.


:bust_in_silhouette: Reply From: Wakatta

There are many ways to achieve what you want to do and state machines (FSM) are by fare the best option since you can do multiple things with the same key bindings.

State Machine


extends Node


var state = STATES.IDLE

func _change_state(new_state):
    state = new_state

func _input(event):
    match state:
            if event is InputEventKey and event.scancode == KEY_W:
                if is_near_door:
            if event is InputEventKey and event.scancode == KEY_W:
                if is_door_opened:
            if event is InputEventKey and event.scancode == KEY_W:
                if is_door_opened:


2D Finite State Machine

This seems to be very advanced!
Not sure how to implement this.

For the moment I’ve found some kind of workaround with variables.

If door == 0 (the character is not touching the door) then every button is abled;
if door == 1 (the character is touching the door) all keys are disabled except the UP button.

That seems to work as expected.


Pancotto | 2022-11-10 09:01

What you’re doing is creating a bool switch.

var door : bool = false

if not door:
    door = true

However there are only 2 possible states that work like a light switch off and on and for your type of game as it grows in complexity consider using FSM as it works more like a traffic light.

Wakatta | 2022-11-10 10:02