Game Development Reference
In-Depth Information
The shoot action
Shooting is the first action that directly interacts with another agent. In order to apply dam-
age to another agent, we need to modify how the soldier's shots deal with impacts. Previ-
ously, when the soldier shot bullets out of his rifle, we added a callback function to handle
the cleanup of particles; now, we'll add an additional functionality in order to decrement an
agent's health if the particle impacts an agent:
Soldier.lua :
local function ParticleImpact(sandbox, collision)
Sandbox.RemoveObject(sandbox, collision.objectA);
local particleImpact = Core.CreateParticle(
sandbox, "BulletImpact");
Core.SetPosition(particleImpact, collision.pointA);
Core.SetParticleDirection(
particleImpact, collision.normalOnB);
table.insert(
impactParticles,
{ particle = particleImpact, ttl = 2.0 } );
if (Agent.IsAgent(collision.objectB)) then
-- Deal 5 damage per shot.
Agent.SetHealth(
collision.objectB,
Agent.GetHealth(collision.objectB) - 5);
end
end
Creating the shooting action requires more than just queuing up a shoot command to the
animation controller. As the SHOOT command loops, we'll queue an IDLE command im-
mediately afterward so that the shoot action will terminate after a single bullet is fired. To
have a chance at actually shooting an enemy agent, though, we first need to orient our
agent to face toward its enemy. During the normal update loop of the action, we will force-
fully set the agent to point in the enemy's direction.
Search WWH ::




Custom Search