How do I create a "dashing" function

Get help using Construct 2

Post » Sun Jun 29, 2014 3:17 am

Hello folks,

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?

Thanks.
B
4
Posts: 11
Reputation: 322

Post » Sun Jun 29, 2014 3:22 am

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.
B
6
S
1
Posts: 73
Reputation: 571

Post » Sun Jun 29, 2014 5:27 am

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.
B
4
Posts: 11
Reputation: 322

Post » Sun Jun 29, 2014 6:29 am

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.

http://www.scofano.com.br/sandbox/dash.capx
B
34
S
5
G
1
Posts: 164
Reputation: 2,725

Post » Sun Jun 29, 2014 9:16 am

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.
B
4
Posts: 11
Reputation: 322

Post » Sun Jun 29, 2014 3:03 pm

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.
B
34
S
5
G
1
Posts: 164
Reputation: 2,725

Post » Sun Jun 29, 2014 6:59 pm

Message: guy23 is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
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.
B
4
Posts: 11
Reputation: 322

Post » Sun Jun 29, 2014 6:59 pm

Drop box.com/s/68k9e0uhm709u0i/Example%202.capx
B
4
Posts: 11
Reputation: 322

Post » Sun Jun 29, 2014 10:33 pm

404
B
34
S
5
G
1
Posts: 164
Reputation: 2,725

Post » Sun Jun 29, 2014 10:47 pm

HI Scofano, I tested the link. Just need to remove the spacing and it should be alright. Thanks again.
B
4
Posts: 11
Reputation: 322

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 25 guests