IA Logo


IA Information
Communication

Dave Mark's books

Post-Play'em - Observations on Game AI


Call of Duty 2: "I saw that grenade coming!"

Another quick observation from my perusal of “Call of Duty 2″ for Xbox 360. I’ve noticed rather often that, when I toss a grenade, the intended “recipients” seem to know that it is coming as soon as it leaves my hand. They will yell some German variant of “Holy crap, there is a grenade! Run, dude!” This is all well and good if they are seeing the grenade coming and would like to amscray prior to its arrival. However, the quirky behavior comes in when I am doing something like bouncing it off a wall around a corner. I will hear them shout prior to the offending pineapple even making it to the corner that I am trying to circumnavigate. In other words, they either saw the grenade through the wall, or there is some sort of mirror-like sheen on the wall that allows them to see it coming.

The programmers seem to be using a messaging architecture wherein an event triggers a reaction in all agents within range. For example, if the grenade were to explode in front of them, the explosion itself would send a message out to nearby agents saying “if in range, die violently”. Messaging architectures are opposed to polling architectures where the agent is constantly looking through his environment to see if there is something to react to. Using the same example, the agent would constantly have to scan the nearby world to see if a grenade has exploded. Since grenade explosions are relatively rare, this would be a lot of wasted CPU. As you can see, messaging architectures are more efficient for event based situations.

In this case, the landing area of the grenade is roughly calculated. If the projected landing spot is near an agent, they react appropriately. They yell out warnings and move away if necessary.

However, the programmers would have faced a quandary as to when the grenade itself should send a message. If you wait until it lands or bounces off of something, it would discount the very possible scenario that they could have seen it flying through the air in the first place. If it is triggered when it is thrown, it creates the issue I observed above – that they know it is there despite the fact that they should not be able to see it at all.

One solution (albeit not a very efficient one) would be line of sight checks along the path of the grenade. Once a grenade launch has happened – and a message dispatched to the agent – the agent would now have to do a line of sight (LOS) check. If the grenade is visible, all is well – react appropriately. If it is not visible, the agent would have to change techniques to a polling architecture specifically doing periodic LOS checks at the grenade. When you consider that there may be 10 or 20 agents (friend and foe) in the area, multiple grenades in the area, and each agent-grenade LOS check would need to be done many times per second, the computational overhead adds up very quickly.

Another potential workaround would be to create a plane that is the intersection point of the path of the grenade and the visible area of the agent. At that point, the “see grenade” event can be triggered once the grenade passes that point. That seems to be not much of an improvement since there would be as many planes as there are agents and the grenade would now have to poll the planes many times per second. The overhead would be similar to the first example.

There is another way of handling that, however. Once the plane is generated, the distance from the source to the intersection of the plane can be calculated. Since the velocity of the grenade is near constant, the time delay until the projectile reaches the plane can be established. The message can be sent with a delay of x number of frames (or any other way that the game loop timer is built) so that the message is delivered and activated at the point that the grenade would have come into sight. No polling is necessary at this point. Just like before, a single event message is sent. The only additional overhead would be creating the planes representing the lines of sight for the agents in the area. In fact, if the LOS check is successful at the beginning of the throw, the plane creation is not even necessary. If an agent is going to yell to his squadmates about the throw, you don’t need to do LOS checks for them at all – they already know. It would take some testing to find out how much overhead this eats up, but the result would be that you could do stealth/surprise grenades in a much more realistic fashion rather than the current “I saw it coming around the corner” effect.

(More observations of “Call of Duty 2″ for Xbox 360)

Tags: , , , , , , , , , ,



12 Responses to “Call of Duty 2: "I saw that grenade coming!"”

  1. Markus K says:

    The last suggestion would only work if the NPCs would remain stationary with a fixed view position. A quick optimization would be to check if the grenade is in the FoV before doing those expensive raycasts.

    Just my 5 €

  2. Dave Mark says:

    Rather a good point there. Thanks!

  3. kometbomb says:

    Do keep in mind raycasting isn’t THAT expensive on a modern platform. In a world in which a simple 320×240 raytraced scene renders real-time without any optimization at all, a few hundred rays a frame shouldn’t be that hard for an average computer.

    I do agree that this is extremely annoying behavior in games, though. :)

  4. Anonymous says:

    Why not just have the grenade do the LOS check? If it ‘sees’ the soldier, THEN the soldier is given a cpu message to react. Seems like a simple work around.

  5. Dave Mark says:

    Uh… Hmmm… That is way to smart. I suppose if I had bothered to think this through rather than griping about it, I may have come up with that myself. Good work!

    Too bad you were anonymous!

  6. Anonymous says:

    having the grenade see the soldier would work some of the time, although it would have the original problem if the enemy is facing away from it.

  7. Jon says:

    Well, if you wanted to involve realism, then an entire bevy of considerations need to be made. On pin-pull, a message should be sent to alert the senses of units within audible range (accounting, of course, for ambient noise), triggering some units to begin a turning maneuver to see the source of the sound, this message would also come on any collision with walls, ground, etc. A “paranoid” unit could react to this by shouting as well. Once you’ve accounted for audible stimuli, then I think the best solution is a two-part polling/messaging system. The grenade receives replies from its “launch” message from all necessary units defining each of their respective visual “cones”. It then has the responsibility of notifying each of those cones as it intersects (becomes “visible”). Each unit, in turn, is responsible for notifying the grenade to update its cone position/orientation upon movement. This allows for units to be moving, and with a little creative code, also to allow for less perception on peripheral vision than within centralized sight. A little more memory would be used to store multiple sets of visual cones, but the relative rarity of grenade interaction would keep this a negligible hassle.

  8. Dave Mark says:

    Nice… ;-)

  9. Frank says:

    Just a passing thought to give increased realism as well as lighten the load a bit… Just start counting from the bounce.

    Think about it, if you bounce a grenade off a wall then it will be clearly audible. This should cause the soldiers in the target zone (or the close vicinity) to turn. First one to have FOV of the grenade yells.

    This version has the added benefit of adding a realistic reaction time.

    For lobbing grenades over obstacles, send the signal as the grenade passes the peak and starts to descend. First hostile to get FOV of the grenade, shout and run.

    Of course for the sake of realism it would be nice if you add a randomizer in there, give each enemy a percentage chance to notice the grenade at all if it is not already in their FOV.

  10. MarcusBrutus says:

    Or maybe, just maybe, they can hear when you remove the pin from the grenade and the striker lever rings out (just like real life). *Click* *shing*

    Here’s a diagram of a grenade for those that don’t know what a striker lever is. – http://www.howstuffworks.com/grenade2.htm

    You couldn’t seriously think that game developers would make such a blatant flaw without an explanation did you? ;)

  11. Dave Mark says:

    Sure… guns blasting, artilery booming, people screaming… and someone asks “Uh… did you just hear a tiny grenade pin getting pulled?”

  12. Anonymous says:

    Who knows where to download XRumer 5.0 Palladium?
    Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Leave a Reply

Add to Google Reader or Homepage




Content 2002-2018 by Intrinsic Algorithm L.L.C.

OGDA