This is a school project that I did a lot more than I had to do. The main goal of this project is to show my understanding of using different random distributions in code.
I used Perlin noise to generate the terrain, and I can change it to whatever kind of shape I want just in the editor. For the dinosaurs, I used a non-uniform distribution to make it so that there are more towards the front, and less in the back. The leaders(little animated guys standing on two legs) are scaled in the Y axis using a Gaussian distribution. The walk pattern that they have is also randomized to the left and right a little bit. The trees and rocks are just randomly generated within the bounds of the terrain itself. There is a problem with that which I have not fixed yet, which is that they spawn inside of the rocks and other things too.
What made me go above and beyond on this project, was that I turned it into a small game. I added a first person controller from Unity, and gave the player a basic shoot/reload sequence.
For the shooting I used ray casts. Each dinosaur has 3 hit points, and on the third hit they are destroyed. To play the animation of the small explosion going off, I used the RaycastHit variable’s point property to make a new explosion wherever the raycast hit.
I also did more than I had to when it came to aesthetics. I added in rocks around the border of the terrain. Because the terrain is generated randomly, and the Z value will always be different, I had to make a small script so that every time the game starts, the transforms of anything with that script on it will be set to the terrains Z value at the X and Y coordinates of that object.
All assets that I imported or used in any way for this project are listed in the documentation file for it on GitHub.
The is a simple little demo that I did for one of my programming classes which shows that I know how to use basic trigonometry in code. There were two main goals for this project.
Have the hand on the clock follow the mouse cursor through code.
Have the numbers of the clock be generated through code as well.
To have the mouse follow the cursor hand I used the following code:
// Gets the mouse location from the screen
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// Use the Mathf.Atan2 function to get the angle at which we need to rotate
float angleFromCenter = Mathf.Atan2(mouseWorldPos.y, mouseWorldPos.x);
// Since the angle input from Atan2 is returned in radians, we have to
// convert it to degrees in order to use the Quaternion.Euler method.
float degrees = angleFromCenter * Mathf.Rad2Deg + 180;
What this small project does is generate terrain patterns in Unity using 2D Perlin Noise. The script that I wrote for this demo is very reusable, but does have to be put on a terrain object for it to work, or at least something with a Terrain Data component. The main part of this script is the method where I loop through the TerrainData component’s height map, and set each value equal to a Mathf.PerlinNoise value.
The fields for this script are simple:
A private TerrainData object
A public Vector3 value that is used to apply the size of the terrain that you want
A public int so that you can adjust the Terrain heightmap Resolution
2 public float that are limited to a range of between 0.0 and 1.0. I use tha [Range(0,1)] modifier here so that it is a nice slider in the Unity Editor, making it easier on me and others in the future.
Here is what the inspector looks like for this component
This was a class assignment for my IGME 202.04 class(Interactive Media Development), with Professor Erin Casciolli, and I did get a 100% on it.