0 votes

So I am making a fighting RPG game where there will be a few button combos. Currently I have made the four direction walking but now i want to make it so pressing up twice or down twice will make the player run in said direction.

Any tips on this? Or tutorials?

in Engine by (202 points)

1 Answer

+1 vote
Best answer

Hey Skydome,

one way would be to check if the player is already walking in a given direction:

var walks = null

func _process(delta):
     if Input.is_action_just_pressed("walk_up"):
         if walks == "up":
              speed = 200
         else:
              speed = 100
              walks = "up"
     elif Input.is_action_just_pressed("walk_down"):
         if walks == "down":
              speed = 200
         else:
              speed = 100
              walks = "down"
    # ...

NOTE: This way the player could wait infinitely before pressing the second time. You could use a timer to reset the walks variable like in the example below.

Another way would be to have a list of actions that were done before:

var actions = []
var timer = Timer.new()

func _ready():
    timer.one_shot = true
    timer.connect("timeout", self, "delete_action_history")

func _process(delta):
    if Input.is_action_just_pressed("walk_up"):
        if actions.back() == "walked_up":
            #run up
        else:
            #walk up
        do_action("walked_up", 1)

    #...
func do_action(action, time)
    timer.stop()
    timer.wait_time(time)
    action.append(action)

func delete_action_history():
    actions  = []

This system would be more advanced and could be easily adapted to more complex combinations as it would also allow to create something like this:

if Input.is_action_just_pressed("jump"):
    if ("jumped" in actions) and ("ate_berry" in actions):
        # jump again

This will allow your player to make another jump if he ate a berry during his jump.

It's not completely perfect but it might give you a hint how you could do such a thing. Hope it helps.

by (830 points)
selected by

Hi thanks for your reply.
Timer is how I was thinking of doing it. My game is a fighting game so there will also be other combos for fighting. A bit like little fighter or dragon ball z Buu's fury for GBA.
Do I need to use a timer node for this to work?
Again thank you for your reply.

You don't need a timer but if you want it to be time based (your "action_history" clears after some seconds), yes you need (a) timer(s). It depends on what your game should be like :)

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.