• Nothing
  • About
Menu

Asher Einhorn

  • Nothing
  • About
snake.png

How would we script... The grenade-shooting moment from MGS5

June 22, 2015

https://youtu.be/tXf1xKiKKu0?t=20m35s


In one of the recent MGS5 gameplay videos, there is a moment where the protagonist throws a grenade, only to have their companion AI shoot it into a helicopter that was otherwise almost impossible to take down. It's the kind of over-the-top action we've come to expect from Hideo Kojima, but how would we implement something like this into one of our own games?

There are of course always an enormous amount of ways this can be done. Here, we'll look at just two:

  1. As a script attached to the helicopter
  2. As a more generic action available to the companion AI

The key here is to really start thinking about how we would structure the underlying code to give us the building blocks we would need to not only script this event, but many like it. Let's think about the steps involved.

As a script attached to the helicopter

We might want to attach this script to the helicopter if it's a non-generic action that can only occur when the helicopter is present.

  1. First we would want a generic way of testing for certain objects based on proximity to other objects, in our case, the helicopter
  2. We would then want a system that let us query by object type, so again for us, this would be the grendade
  3. We would probably want to extend this to check to see who threw the grenade, and check for the player as the owner
  4. Next we would want to check that the grenade was on the same side of the helicopter as our companion AI
  5. The companion AI would then be sent a signal to shoot the grenade
  6. Finally we would add the approprioate velocity to the grenade and destroy the Helicopter

With this piece of logic we could write an event that would happen naturally if the player ever ended up in this particular situation. More importantly though in writing generic functions to let us query for objects, owners, positions and so on, we give ourselves the ability to script more events like this, that are equally as unique, very quickly.

Maybe we could make it even more generic though. Let's take another approach.

As a more generic action available to the companion AI

In all honesty it might be a better idea to code this as a generic action that the companion AI possesses, so that they can use this on multiple types of enemies. This is now not then a scripting task, but it's still good to think about the steps involved.

Here we would probably want the AI to be constantly positioning in a way that is helpful for the player, again this will be something core to the way the AI is coded so is not really a scripting task. You can see in the demo that the AI jumps next to the player before jumping away, signposting her position so that they can better choose to use the action. Then, when a grenade is thrown, the AI will perform a cone check to see if the grenade is going to move in between her and an enemy, and if it does, shoot it towards them. This will give the AI the ability to shoot multiple objects at multiple enemies given the right positioning, and in doing so may result in some interesting opportunities for emergent gameplay.

In actual fact there is an extra step in the video - the player actually asks her to perform this action, but it's not really relevant to the core of the explanation.

In Scripting Handbook Tags Scripting, Tutorial
← The link between space and mechanicsState machine messages →
Twitter
  • RT @CKapmeh: Sunday Capilla San Bernardo / Nicolás Campodonico https://t.co/V56q7uftPf
    May 28, 2017, 10:42 AM
  • Crunch dadaism. Come to @Naughty_Dog and experience the highs of creative culture. https://t.co/9yMPcTdiYA
    May 27, 2017, 9:33 AM
  • Crunch garden #gamedev Avocado, Lemon and Peppers. From right to left. https://t.co/jtZXeWDEgh
    May 27, 2017, 9:31 AM
  • Working with a migraine two days in a row is quite possibly the most unpleasant thing in recent memory.
    May 26, 2017, 3:36 PM
  • Sure is fun to have a night off! #PS4share https://t.co/WMcEMY5yWE
    May 21, 2017, 7:59 PM
  • The EU/US PSN account conflict is an ongoing nightmare. Looks like I'm not playing anything tonight after all.... pain!
    May 21, 2017, 7:49 PM