Roll Over the Obstacle- Game Dev Series 96

Objective: create a rolling action to cross the obstacle.

We will create the rolling action in today’s article. Rolling action is quite iconic action in action game. It can be used to cross obstacles or avoid dangerous.

This action movement is also based on “animation play first, character move later” concept. You will need to import the animation to finish the following proceed.

Animation logic

The timing of doing rolling is very specific, we only need to do it when we are running, which is the good place to make an animation state.

We need a trigger to start rolling when running, create a trigger as parameter and assign it to the transition.

When rolling is finished, just let it transit back to Running after playing.
Now we can active the trigger in script.

Let’s roll

Same as grabbing on ledge, it would be less buggy if we disable CharacterController when we are rolling. To do the rolling, we can use left shift to start this action.
Create an if statement to check the input inside Player animation turning checking function.

We can do the rolling now. However, it would snap back to the origin position immediately. We need the animation state behavior script to fix the position issue.

Before we add the behavior script, let’s create an empty object to store the position after rolling.
Same as we locate the clime up position from ledge, duplicate Player to mark the position when after rolling.

Remove all the unnecessary components just keep transform. We will use this position in script.
Create a gameobject variable in Player script and assign the one we just created. Now we can create an animation behavior script.

As usual, get the reference of Player script in OnStateExit() of RollingBehavior script. Before that, we need to create a public method in Player script to handle repositioning.

Call this method from RollingBehavior script.

All set! Player now would snap to the position after rolling.

Fix opposite rolling issue

There is a tiny problem we need to fix. When we rolling to the right, everything works fine. However, when we rolling to the left, the snapping position still be on the right.

We need another gameobject to locate snapping position to the left.
Duplicate the gameobject and readjust the new one to a proper position.
Then we need to make the system checking which gameobject should use as goal position.

The easiest way to check the facing direction is using localEulerAngles, which we used to rotate Player model.
Use it in an if statement.

All done! Rolling action is perfect now!

--

--

--

A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Objects and its Internal Representation in Javascript.

Why do we need Streams in Node.js?

📷 React.Sydney 45

Creating a Spotify Companion App

How To Fix Memory Leak Issue In React Js Using Hook

Don’t blame me, I am “not” JavaScript

While vs Do…while loops in JavaScript

How to change the speed of a Facebook video

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Adding a thruster speed boost on keypress

What is a Control Track in Timeline

Cat Facts: UnityWebRequest

Upgrading A Unity Project To The Universal Render Pipeline (URP)