Saturday, 4 August 2012

Beginning Combat: Ranged Attack / Shooting

As part of Caruso's repertoire of actions and abilities in game, he will be able to execute various attacks in order to defeat the enemies that he will encounter throughout the levels of the game. The first attack type, ranged attacks (projectile/shooting attacks) have been the first type of attack to be implemented in the test environment builds in order to shoot and defeat the enemy mini tumblers that populate the test environment level.

How it works:

When the player presses the ranged attack button on the controller, a newly created script called 'combat' receives this button press and executes a function called 'Shoot' within the script. The 'Shoot' function then first checks the last time a projectile was fired using the shoot function by comparing the current game time with the time saved when the 'Shoot' function was last executed. If the time difference is more than the defined waiting period between shots, the shoot function will be allowed to continue.
Next, the object that will serve as the projectile is instantiated at the defined spawn point in front of the player character and the relevant parameters, such as the object tag, are set to make it identifiable as a projectile from the player character. Rigid body and collider objects are also applied to the projectile object to make it able to collide with the enemy characters.
Once this is done, the movement direction and rotation is set so that it will fire in the direction the player is facing, then a force is applied to the object to make it move in that direction at a constant speed.
If the projectile object is in the game for more than 5 seconds and it hasn't collided with an object, the script will then destroy the object to prevent lost projectiles from building up over time.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.