Thursday, November 15, 2012

Projectile Mechanics

I implemented a system that would allow the guards to fire projectiles at the player. To start, I simply needed to launch a simple projectile. Thus, I modeled a system that let the enemy take in the player's position, create a projectile at the enemy's position, then propel the projectile towards the player's position every update cycle with a given velocity. A relatively simple function, so I expanded the functionality a bit.

First, I developed a projectile manager that would handle any and all projectiles that a guard may use. This would provide a method to create and delete any projectiles that belong to a particular guard. 

Second, I implemented a hit detection method for the projectiles. Every projectile would check, every update cycle, whether any of the current player's were colliding with it. The function would return true if a player was colliding with it, and false otherwise.

As of now, it works pretty well.  I added a timer so the AI would only fire a projectile every x seconds, and it seems to work well in testing.  I did have some problems manipulating the angle of the projectile at first, but I worked it out to face properly.  I'll be refining this system to include all types of projectiles, and to compute smarter paths over the next week.

No comments:

Post a Comment