Devlog #02 - Implementing Dash Mechanics


Introduction: 

As per the next plan from the previous dev log, It was to implement the dash mechanics so players could move out of the way of the attack. Dash is the last-minute survival tool if hiding behind the obstacle doesn't work, Hence we wanted players to have that option to do so. This could add new twists if the opponent is ready to do the final blow and you are still surviving.

Initial Logic:

The aim here was to create dashing in different directions possible, which could enable players to decide where to go next. This is done using the movement keys to fix the direction of the dash. So to do so we needed to get the movement vector generated as well, and get the float value which is either 0 if the player is not dashing or 1 if the player is dashing, and Multiply it with the movement vector generated.


Dash vector calculation
This script is done in GameInput.cs
 


So now we have the direction of the dash itself. The next part is where I did the actual moving of the character.

This was initially done using the  transform.position as shown below,

transform.position = transform.position + dashVector * dashSpeed

This technically did the dash or it was more like a teleportation to the calculated position.

The Bug with the initial idea:

Then while testing I found a bug I.e. the player could dash out of the bounds of the map or through any solid obstacle. Since it acted like a teleportation. This should not happen.

The Current Logic:

So I had to scrape that and figure out a way in which players could dash while keeping the collision on. This was done using Rigidbody. So Rigidbody lets the models have the physics system and hence cant have the player passing through obstacles like before.

Now I tried to apply the same logic using Rigidbody but it didn't work. So then I came across Rigidbody.AddForce() which let's you add an Impulse for propelling the player forward.


Dash script
This script is done in ArenaPlayer.cs
 

Then there also was another problem that arose I.e. nothing was stopping the momentum and it could carry players far. This is not something I had in mind. I wanted the players to be able to dash to a predicted position and not let momentum carry the player. So I worked on fixing that along with adding a cooldown for the dash so the player cant keep spamming it and is utilized in a valuable time.

This is done by applying a velocity equal to a zero vector after a dashTime period. And the cooldown also followed the same logic so had that done too.


Dashtime and Cooldown manager
This script is done in ArenaPlayer.cs
 


Final Steps:

The final step is to add controller support. The following bindings were added:

  • Movement - WASD / Left Stick (Controller)
  • Dash - Spacebar / B (Controller)

Final Output:

So What's next?

As per the plan, the next step is to implement shooting mechanics, so the player can do some damage and eventually defeat the opponent.

References:

[1] Unity Rigidbody: https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Rigidbody.html

[2] Unity Rigidbody.AddForce() : https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Rigidbody.AddForce...

Leave a comment

Log in with itch.io to leave a comment.