So I’ve decided to start a new tutorial series on how to create a Pac-Man Clone in Unity 5.5. The tutorial like all others can be viewed on the Weekly Coder YouTube channel. You can click the link below to watch.
Be sure to stop by weekly for new videos in the series.
Below are the assets available for download.
If you didn’t read part 1, and want to get background on sine waves for game development. Click Here (PART 1).
If you did read it, or don’t care, please continue.
Last time it was all about the basic sine function and how to make game objects move in the shape of a sine wave. This time let’s take it a step further. I’m going to show you a few more practical applications of sine waves, that isn’t limited to just moving objects.
I think I used the word oscillate more than 6 times in the last post, but it’s the essence of sine waves. This post isn’t going to be too long, since I think you’ll catch on quick if you haven’t already. Basically what I’m telling you, is that if you want anything to smoothly move back and forth (oscillate) between two states, values, locations, etc, USE THE SINE FUNCTION.
Don’t worry, this isn’t going to be a whole Trig class. I will however, go over one very useful trigonometric function that is easily overlooked by beginner, and even veteran game developers. The Sine Wave. Hopefully this will fuel your own curiosity to learn more about trigonometry and how applicable it is to the world of game development.
If you know what the Sine function is, fantastic, if not, I’m sure you’ve heard the term. You may have encountered it in high school geometry or trigonometry, and it’s applied in just about every field that involves some kind of math.
Sine waves are a graph of the Sine function, and given a basic form, as the input value changes, the output will oscillate between 1 and -1. Here’s what that looks like:
Note: You may notice that the sine wave perfectly maps to a circle of radius 1. That form of circle is called a Unit Circle. Understanding it is helpful but not necessary. As I said this is not a trig class. Moving on.
While working in Unity I found it difficult to figure out how to get an object to rotate. If you’re reading this, you probably did too. Right now I’m just talking about 2D game object rotation. The concept works in 3D as well, just turn on a different axis, but I won’t go into that here.
If you don’t feel like reading the article and just want the Full Script… skip to the bottom.
Add this to the property section of your class:
public float degreesPerSec = 360f;
This will be the variable that tells the script how fast to rotate around the axis. It’s in degrees per second. Feel free to play with the number as see how it affects the rotation speed.