Everdevs Community
Published in

Everdevs Community

“Funslingers” Devblog #25 | Adding a Dodge Ability in Unity

Hey Devs!

Now that we’ve created a solid base game, where there is all the functionality and core features we need to call it complete. We can start adding extra features that will further the depth of this game and really set it different than other games in it’s genre!

So, the first fun feature we can add to vary the gameplay a bit more, will be a dodge ability! If the player ends up in a sticky situation and needs to make a quick escape from a wave of bullets, the player can dodge roll away and be protected from incoming fire!

So let’s start by creating the trigger for how I want the player to activate this ability.

We’ll bind this ability to Left Shift since it’s similar to a sprint feature, and we’ll call a Coroutine for the ability since the dodge should last about 1 second, so we can program around a WaitForSeconds() delay.

We have a second if() statement for different directions, since the player should be able to dodge left or right. So we can pass in a simple integer that we can handle with a switch statement inside the Coroutine.

So in our Roll Coroutine we have a mixture of a lot of other methods we’ve used for other features. First, we activate our roll animation, then immediately set all our bools to stop the player from being able to move, shoot, take damage, and roll again. Invincibility was done through a very simple if statement I added to our LoseLife() method.

Next, in our Coroutine I have a switch statement which will take the integer representing the direction the player is moving and rotate the player to face that direction.
After that, the Coroutine will wait the approximate amount of time of the roll animation, and reset everything back to normal!

Lastly, we get our Roll Animation and plug it into our Controller!

With the way I’ve set up the animation controller, the player will only able to roll while they are in a strafe animation, so only while they are currently moving. Then once the animation is over, it will immediately return to the player’s idle animation, ready to start strafing and roll again.

With this animation in place, our player can now roll away and dodge incoming bullets!

--

--

--

Game dev tutorials and news about Everdevs.

Recommended from Medium

Top 10 ios Application Development Companies In UK

Case study: The pursuit of flow (Part 1)

How to Run a Windows Machine on Mac

No-Code & The Future of Programming

Setup Web Application Stack using AWS Services for Starter (+ PHP/Laravel mini-setup)

Lessons learned in Agile QA testing

NetSuite’s automation capabilities: Your next best new hire

Normal distributions are all around us and the human brain is pretty used to

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ethan Bristowe

Ethan Bristowe

Passionate self taught game developer excited to learn and share everything I can about game development!

More from Medium

Unity: Building and Deploying WebGL game

Script communication in unity using GetComponent:

Optimization — Caching WaitForSeconds In Unity Coroutines

Saving Data in Unity3D Using Files