Entity Scripting: Melee and Ranged Combat
Design Goal: To script melee and ranged combat from scratch for third-person gameplay.
Description: Melee combat involves Alyx constantly swinging a crowbar in front of her, dealing damage to objects in front of her and knocking back enemies. Ranged combat involves Alyx aiming a fire crossbow and shooting every 1.5 seconds, killing enemies. Only one weapon is equipped at a time. Alyx starts with just the crowbar and later picks up the fire crossbow. While attacking, Alyx moves at a significantly slower rate.
Design Challenge: Since Half Life 2 was not designed to support third-person gameplay, combat was not as simple as assigning Alyx a weapon. The Crossbow specifically, was only used by the player character in Half Life 2. Therefore, all the functionality for the weapons had to be scripted.
For melee combat, two volumes are attached to the crowbar that only activate when the player is both using the crowbar and holding the attack button down. One damages enemies and the other applies a knockback force. Additionally, an attack animation is played and looped for Alyx when the crowbar is being used.
For ranged combat, an invisible func_tanklaser is attached to the crossbow and aims at an invisible target that is also attached to the crossbow. Alyx plays a shooting animation and the func_tanklaser fires at its target. While the player holds down attack with the crossbow equipped, a red targetting laser appears letting them know where the crossbow is going to fire. The crossbow automatically reloads while holding the attack button and has no ammo.
When either weapon is in use, a trigger_ playermovement attached to the player is activated, causing the player to move at a reduced speed. Once the player has earned the crossbow, '2' switches weapons to the crossbow and '1' switches weapons to the crowbar.
For melee combat, two volumes are attached to the crowbar that only activate when the player is both using the crowbar and holding the attack button down. One damages enemies and the other applies a knockback force. Additionally, an attack animation is played and looped for Alyx when the crowbar is being used.
For ranged combat, an invisible func_tanklaser is attached to the crossbow and aims at an invisible target that is also attached to the crossbow. Alyx plays a shooting animation and the func_tanklaser fires at its target. While the player holds down attack with the crossbow equipped, a red targetting laser appears letting them know where the crossbow is going to fire. The crossbow automatically reloads while holding the attack button and has no ammo.
When either weapon is in use, a trigger_ playermovement attached to the player is activated, causing the player to move at a reduced speed. Once the player has earned the crossbow, '2' switches weapons to the crossbow and '1' switches weapons to the crowbar.