I'm trying to make it so my player will dash in the direction of the key if it's pressed twice. For example you tap W twice and the player will dash upward. I've looked around but I've found no confirmed methods or the demo files were simply lost. What do you think is the best way to go about this?
The first method that comes to mind is to create a local variable and start a timer every time you press the directional key and once the timer runs out you change the local variable.
You start the local variable with "no dash" and when you press the directional key for the first time it will change to "dash possible".
After the timer has run out the variable will change back to "no dash".
While dash is possible, pressing the directional key again will trigger the dash function.
You will have to make this for every directional key if you plan on being able to dash every direction.
The timer will of course be very small around 1 second.
Hopefully this helps you in the direction of what you're trying to do.
Thanks reza for the response. Though I'm having some trouble implementing it. I have a global variable called "CanDash" that's set to 1 once the player presses the relevant button, and I just recently switched over to a local variable. But I cannot get to any point where I can set the keyboard to be pressed again for that function. I've tried the "While" condition under system, but I get nothing.
See if this helps you out. It's basically what reza just said.
Double press left or right for "teleport dash"(replace with your desired movement).
Global variable controls the sensibility.
Thanks Sofano, although my game is a topdown shooter your example did help me get an understanding of what to work towards. Though, my player gets stuck to the sides of the map and cant move normally when I apply your code into the basic 8 move functions. On a sidenote my monsters also seem to have lost interest in the player, lol.
Try to add "bound to layout" behavior on your ship and instead using move f, try acellerate or a speed boost my example "teleports" to position. Replace that part and you are good to go.
Hello Scofano, and thanks again for the help.
I experimented with your example a bit to see how it'd work on 8-Directional movement. Hortizontal movement now works perfectly, for vertical movement I made a new global variable just for that. I can get the ship moving upwards but when i do downwards it just keeps going up. Perhaps there's something I'm missing here. I uploaded the file since that'd do better explaining than I could.
HI Scofano, I tested the link. Just need to remove the spacing and it should be alright. Thanks again.
I got your capx.
My example wont work with 8direction the way it is now.
If you are using 8direction you dont need mirror or flip, as the behavior can do it for itself. You will need to separate left, right, top and down variables and different dashes for each one.
Use the technique (time and global variable) to make left. Then, create all over again for right, and so on... If even tough you can't make it, drop me a line.
Thank you Scofano and Reza for your help! I managed to get it working now, all it needs is tweaking and proper implementation. I've uploaded the file incase anyone else would like to see how it can be done
drop box com/s/vm7l77q6655zry4/Working%20Dash.capx
Hmm, I noticed when I tried to implement it into my main project I still get the effect of the player dashing forward but from only one button press. This is when I'm using the WASD control scheme, with the Directional Buttons everything works as it should.
add another event and put OR "press left' OR "press A"
Develop games in your browser. Powerful, performant & highly capable.
I must admit to being lost on that one - I can surely add an event, but when it comes to adding OR operators with keyboard functions, I don't really know where to go from there.