Sun Run: Adding Some Runner Mechanics

I hope everyone had a good weekend! It was a holiday here, which is why I slowed down development (to work on a different project actually, but also see The Edge of Tomorrow and play Shovel Knight, both recommended) but now I’m back!

Let me talk about how I went from having some sprites to having a bit of a game…

First of all, I want to give credit to the resources that have helped me with this project. One resource that has helped me out a lot is Jesse Freeman’s Unity training, and his book, which gave me some useful code for creating enemy spawns in the game. I won’t replicate that code here, but with some info in his book, I was able to create three different spawn points to spawn enemies on the board, which will fly toward the player. The first enemy sprite is a bird drawn with basically the same method as the horse sprite. You can see the graphical representation of these spawns in this working shot here, on the right:

unity-showingspawns

After a lot of trial and error, I decided not to have the player actually move from the spot. I looked at some endless runner code that actually moved the player, but it seemed to make more sense to actually keep the player stationary and give the illusion of movement instead. Enemies spawning from offscreen to the right was one way to do it, but what about the background? I saw my co-worker Dave Voyles had a great solution for that in his schmup games:

unity-showingiso

If I zoom out of my scene and switch to 3D Isometric view, you can see what’s really going on. There’s a cylinder in the background that shows a texture that’s set to perfectly wrap. The sprites are in the foreground. The code to make the cylinder rotate on its own is really simple…

public class BGRotate : MonoBehaviour {

public float BGRotSpeed = 10f;

void FixedUpdate()
{
// rotate this
transform.Rotate (Vector3.up, BGRotSpeed * Time.deltaTime);
}
}

The transform.Rotate tells it what direction and speed to rotate. I can change the speed of the motion in Unity later, though what I’ll probably do is write a bit more script to speeds things up slowly over time (which would also have to affect the enemy spawns).

The black bars at the top, bottom, and back of the scene are destroyers. They’re used to kill the player if they crash into the ground, and destroy any birds that happen to get past the player, cleaning up the scene. This may not be the most efficient solution for cleanup, but it’s working for me for now. The code for how to get the destroyers set up is in Unity’s Live Training archive under “Let’s Make a Game: Infinite Runner.” I’m linking the whole archive because it’s some of the most useful free resources for learning specific Unity tasks that I can find. It starts out gentle for beginners and has lots of specific code examples for different problems you might encounter!

Next blog I’ll talk about the chariot motion using 2d physics, which was/still is the biggest trial and error point in the game. Want to get that feel just right…


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *