Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Auditory events


Auditory events are created from the sandbox itself and are sent to all agents. It's up to the agent to determine what to do with the information, such as disregarding the event based on the distance.

The BulletShot event

To send an event when bullets are shot, we can update the ShootBullet function to send out an event based on the bullet's shot position:

AgentCommunications.lua:

AgentCommunications.EventType.BulletShot = "BulletShot";

Soldier.lua:

local function SendShootEvent(sandbox, shootPosition)
    local event = { position = shootPosition };
    
    AgentCommunications_SendMessage(
        sandbox,
        AgentCommunications.EventType.BulletShot,
        event);
end

local function ShootBullet(sandbox, position, rotation)

    ...    

    SendShootEvent(sandbox, position);
end

The BulletImpact event

An event similar to the BulletShot event can be sent out when a bullet impacts a location:

AgentCommunications.lua:

AgentCommunications.EventType.BulletImpact = "BulletImpact...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)