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.

Detecting player wall collisions

Detecting player wall collisions - Unity Tutorial

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

Start my 1-month free trial

Detecting player wall collisions

- So now we're ready to modify our collision state to detect whether we're on a wall or not, similar to how we detect whether we're standing or not. Before we do that, you may notice that the wall sometimes appears above or below the ground. That's because they both exist on the same Z position and since we're using quads instead of just straight sprites we're going to need to change their Z value so that they actually appear in the correct order. In this case, I've selected the wall and I'm going to change it's Z depth to 1 which will push this behind the ground. You'll notice that the ground is at the 0 Z depth. Now, let's look into the player and how we can actually detect whether we're attached to this wall. We're going to open up the CollisonState. Now that we have the CollisionState open, let's add a few new properties. Now, underneath standing, we're going to create a property that will represent whether we're on the wall or not. Then, below our bottom position, let's copy out…

Contents