First Game Design (Part 5)

Alright, like I’ve promised…enemies are now in the game! But here’s the thing…its a first attempt at this sort of thing, so it’s starting out simple.

Getting started, as you can see in the featured image above, the enemy is represented by a standard capsule game item. This is just to get the mechanics down prior to implementing a more complex, moving and textured/modeled enemy. Upon creating that enemy, two scripts are needed:

  1. Enemy Health
  2. Damage per Attack

So, first we will start with the Damage per Attack script. This is, as all the other scripts have been, JavaScript and added into the FirstPersonCamera object. Instead of placing the script directly on the camera however, a new empty object should be placed under the Camera which then inherits the script. As far as the script goes, here is what a sample script could look like:Attacking Script.PNG

 

So this script does a few things: First, it sets up an attack damage value. This is set up by the hitpoints variable, which is currently set for 10 damage per hit. You can name this whatever you want, just make sure you remember what its called to reference later. Secondly, it gives a range of attack. If you are standing outside of that range, the damage will not be applied to the enemy or target. This is of course represented by the variable range. Down later in the code a variable DeductPoints is reference which will appear later in the next script.

So, speaking of the next script, this second one will go into the capsule that was created to allow for health points, deduction of those points and ultimatley the ability to destory the enemy once it’s killed or health reaches zero. Here is what that code should look similar to:Enemy Health.PNG

With this, we’ve given the enemy 50 health, which if you remember earlier, we declared our weapon to do 10 damage. This means when the simulation is running, we should be able to hit the object 5 times and it will be ‘destroyed’. The other thing I want to point out is the DeductPoints which I mentioned in the last code. Here, its saying to deduct our attack damage (which is named hitpoints) and take it away from the enemeyhealth (set to 50) each time we are in range and attack with our weapon.

Now we have a stationary target which can be whacked to your hearts desire…until it dies of course. The values presented in this can be altered to your own specifications, but are valid for test purposes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s