O'Reilly logo

Procedural Content Generation for Unity Game Development by Ryan Watkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding character facing directions

The last task we have is to add a functionality that will allow the player to change the direction he or she faces. Then, we can add some functionality that will allow the sword to swing in the same direction that the player is facing. To achieve this, we will have to start in the MovingObject class.

The AttempMove function is where the direction of the player is managed. This is where we can poll what direction the player is moving in, and change the sprite direction accordingly. Code snip 6.9 shows the update that should be added to the top of the AttemptMove function definition:

1 protected virtual bool AttemptMove <T> (int xDir, int yDir) 2 where T : Component 3 { 4 if (xDir == 1) { 5 transform.eulerAngles ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required