From the course: Advanced Unity 2D: Platformer Player Movement

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding ducking to the player

Adding ducking to the player - Unity Tutorial

From the course: Advanced Unity 2D: Platformer Player Movement

Start my 1-month free trial

Adding ducking to the player

- So now it's time to add a new behavior, we're going to let the player duck. In order to do that, we're going to need to create a new behavior script. So let's go into our Scripts folder, Behaviors, and Create a new C# Script called Duck. Then let's open this up in MonoDevelop. The idea behind our duck script is that we're going to take reference of the circle collider attached to the player and shrink it whenever the player ducks. When the player releases the duck button, we'll return the collider to its actual size. In order to do this, first we're going to need to extend our abstract behavior. Then we'll add a few properties to keep track of the collider, the scale, where to offset the collider once we shrink it, and whether the player's actually ducking. We'll start with the public float for scale, and we'll make this .5. So basically, we'll divide the size of the collider in half when the player is ducking. Next, we'll add a public bouillion to keep track of whether we're…

Contents