Friday, March 1, 2013

Update 8: Randomizing the shooting and adding health (and death)


Now that I had a basic level with shooting from point A to point B, I needed to add some randomization. I personally don't like games of attrition, I prefer games of skill, with some luck.

Enter the random number generator. Basically I pass in 2 numbers, a chance to hit percentage, and a random percentage  The two numbers are compared, if it's a hit, no problem, if it's a miss, I created some random variation so that the shot misses and goes off into the distance.

I spent a bit of time trying to create a random shot until I discovered the Random.insideUnitCircle function. Basically I can multiply a variable against it to have it select a random position around my target, which I then just add to my target position.

Finally, to get everything working, I decided to create a test level. I setup a target, with a wall behind it. It works pretty well and is another item I can cross off the list.



No comments:

Post a Comment