Skip to main content

Posts

Showing posts from 2015

Line of sight

I just finished the line of sight detection for a stealth game I'm working on. The characters sight field is made of two rectangles and a circle. The rectangles subtract from the circle making a cone shape. These are children of the character so they follow him and his rotation. I have a script that re sizes and rotates every thing  based on the size and angle of sight you want so it is easy to change the shape of the line of sight cone. When it detects something of interest is in the cone it line cast to see if it is in view. This was my first time doing something like this so I thought I would share to show it off and get some feedback. In this gif a green line is drawn every time the guard can see the player.

Pathfinding

I tried to implement path-finding using a star for the first time. If you are not familiar with a star it is an algorithm that is used to quickly find the shortest path from one point to another. You can read more about it here .  You can see in this first gif that after the two objects are done moving they stack on top of each other. That can be fixed by giving them separate positions to end up at. Right now I click somewhere and it moves both of them to that same exact spot.     In this gif the problem is fixed. The objects are stored in a 2d array and their end position is offset by their index in the array. This way they will always end their movement in formation.    

Random Map Generator

A lot of games use Perlin Noise to generate maps, so I decided I would give it a try. One of the most popular games to do this is Minecraft which uses a similar noise function to create its map.  Landscape generated in MineCraft The basic premise is that you use the noise to create a height map on a 2d grid. Every point on a grid is assigned a random value and that value is its height. If you where to just use a normal random number function to assign the values they would be all over the place. It wouldn't make any natural looking shapes. That is why Perlin Noise is used. It creates smooth gradients between random points. This make the height changes less jarring and look natural. Perlin noise vs white noise  Unity already has a Perlin noise function so I did not have to implement my own. All I did at first was make a 2d array and assign each index a height value. Every height above a cutoff is land and everything below is water, this is the result. It was a lo
Pong Lately I have been overwhelmed with my current project so I thought it would be a good time to take a step back and do something simple. For anyone who doesn’t know, pong is basically a simulated table-tennis game. It was one of the first video games, so I thought it would be a good place to start this blog. I decided to use Unity to make the game. The coding for it was all pretty simple. The ball has a variable for its speed in the x and y direction. Every frame it calls a function that increments its current position by these variables.         There are six surfaces the ball can hit. These are the top wall, bottom wall, right wall, left wall, and one of the two paddles. If it hits the left or right wall that is a score and the game resets. If it hits the top wall, bottom wall, or one of the paddles it bounces off and goes in the opposite direction. I did this by reversing the perpendicular speed variable. For example, if it hits the top or bottom wall the y spe