Create a simple Horizontal Ninja Dash Effect

1
GeorgeZaharia's avatar
GeorgeZaharia
  • 28 Jun, 2018
  • 732 words
  • ~3-5 mins
  • 2,989 visits
  • 1 favourites

While typing the latest examples i also replied to a question today regarding How to Create a Dash Effect for a platformer.

If you don't have the patience to read trough this blog entry and you are here for the example file scroll at the bottom of this page and click the download link.

What we need

for this is 2 Sprite Objects which we will call "Player" and "Shadow", the Keyboard Plugin, and 1 TiledBackground Object for the floor.

For the two sprite i created a little image and set it as their default appearance.

You can download it from here or create one of your own.

On the Player object we add the behavior platform, and create 1 variable called dash and one variable called currentx, we also add the behavior bound by the layout so we don't jump outside the screen when we start the game.

On the Shadow object we add the behavior fade and set its fade out time to 0.2 everything else we leave as default.

We place the Player object on middle of screen in the projects layout and the Shadow object outside, so it gets destroyed by the fade behavior without being seen when we start the game.

We also drop the TiledBackground Object at the bottom of the screen, we add the solid behavior, so the Player can land on it and not pass trough, and finally we set its height at 21 pixels and its length at 900 pixels.

Moving on the event sheet

Keyboard on key X pressed

we add 3 sub-events under keyboard condition and the 1st one will be a OR Sub-event

subevent OR> is Player platform jumping OR is Player platform falling

> Action Player Set variable "currentx" to self.x

> Action Player set variable "dash" to 1

Under the OR condition we add 1 sub-event that will check if dash = 1

Subevent Dash =1 > Action: Player platform disabled;

under the Dash = 1 condition we add 2 more sub-events that will have their own sub-event

the 1st sub-event under the dash=1 will be

Condition

Is Player Mirrored

Is Player X >self.x-100

And the action on this condition will be

Action> Player set X to lerp(Self.currentx,Self.currentx-100,2)

Sub-event

Repeat 3 times > Action Create Object Shadow at Position X>player.x + loopindex*player.width*2 | Position>Y player.y

--------------->Action Shadow set mirrored

The 2nd sub-event under dash=1 will be the same as the above one just in reversed for the main conditions and that is

Is Player Mirrored - Inverted - Right click it and select invert so it only applies if the player is not mirrored.

Is Player X <self.x+100

And the action on this condition will be

Action> Player set X to lerp(Self.currentx,Self.currentx+100,2)

Sub-event

Repeat 3 times > Action Create Object Shadow at Position X>player.x + loopindex*player.width*2 | Position>Y player.y

On the 2nd subevent under X was pressed

We add the following condition and actions:

Condition:

Player Compare X : if X >= self.currentx+100

Action>set dash to 0

Action>Player set platform enabled

Action>set currentx to 0

And one more block the 3rd subevent under X was pressed

Condition:

Player Compare X : if X =< self.currentx-100

Action>set dash to 0

Action>Player set platform enabled

Action>set currentx to 0

We have now to create the animation for the player, so it will face the right direction when we move him and dash.

The last 2 conditions are

New event>Condition: Keyboard>On left arrow pressed | Action> set Player - mirrored.

New event>Condition: Keyboard>On right arrow pressed | Action> set Player - not mirrored.

If we run a preview you will see our little purple ninja that is controllable with the default arrows keys left right up down and when we press up arrow it jumps and if its in the air the moment we press X if he is facing Left or Right the dash will create 3 Shadows that look like him and automatically dissapear leaving a quick trail behind him as a true ninja does when he dashes at light speed.

If you followed the tutorial the right way you should have the event system looking like bellow

For more examples like this or if you have a problem that you don't know the solution to, leave a comment bellow, and i will see how i can help with it.

"Haz file? Give file!" - download.

Subscribe

Get emailed when there are new posts!

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!