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.

Sticking to walls

Sticking to walls - Unity Tutorial

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

Start my 1-month free trial

Sticking to walls

- So in this video we're going to look at how to make the player actually stick to the wall instead of just sliding down it. One of the ways we're going to do that is to manipulate the player's own gravity scale and make him stop once he touches the wall. To get started we'll need to create a new behavior. Let's go into our Scripts and Behavior folders, and Create a new C# script called StickToWall. And then we'll open that up in MonoDevelop. Now we'll need a few properties to make this behavior work. But before we add them, let's extend our abstract behavior. Next, we'll want to make a boullion to keep track of whether we're actually on the wall or not. Let's make this public, type it to boullion, and call it onWallDetected. Next, we'll make two protected properties. One, to keep track of the default gravity scale, and the other, for the default drag. Next, in our start method, let's actually get the values of the player's gravity and drag once this behavior comes online. To do this,…

Contents