Saturday, June 29, 2013

Cockroaches in The Last of Us

Spoiler Free I promise
(Unless you count the roaches as a spoiler)

 


These little guys might go unnoticed in the game but I am particularly proud of them. This was a tag team effort between Eben Cook and I. With a shout out to Nick Lance and Kurt Margenau a couple of awesome designers I work with. Sometimes our effects team might conceptualize an idea but we don't always have the means to create what we want as it requires support from programmers and it's hard to justify pulling a programmer on to something that most likely is not worth their time. I had been exploring our scripting engine in more depth since the end of Uncharted 3 where I had begun using it quite extensively. It's a very flexible scripting engine similar to Unreal Script and LUA based on LISP. I like it. Let me just put that out there. I love things like this because it allows me to think in ways I may not have before. I always like when there is this complex problem to solve and when I come up with a solution I like to admire it's intricacy. Our dedicated effects programmer Marshall Robin, shortly after Uncharted 3, had given us the ability to declare variables in the root data of our particle systems. These variables could be used in our expression when authoring our effects and we could set the values of these variables at runtime. What all this means is we could change the way our particles behaved on the fly. Muahaha. So with all of this in mind Eben and I thought "You know we could totally make some cockroaches that scurry away in some fashion." So Eben setup the cockroaches. They are aligned with their velocity and while they are not being affected by anything they are just randomly moving about based on some expressions Eben setup in the effect. This is where the root data variables (Rootvars as we refer to them) come into play. We basically have this boolean value in the expression that while set to 0 will have them acting normally just moving about and then when it gets flipped to 1 it triggers a condition in the expression to make them scurry in a direction along the z axis of the particle spawner. We simply add some spawners using our level propagation tool and face their z axes in the direction we want them to scurry in.

The next stage is where I had some fun. So I have all the pieces of the puzzle in front of me. I have a set of functions our designers use for other gameplay purposes but I know they will be what I need to get these roaches working. Additionally I didn't want the script I made to be something we could only use once. I wanted it to be something that any other effects artist could just throw into a level and it would do all the work. To do this I needed to be able to let the artist specify the name of the spawners in the level to perform operations on and I had to allow for any number of spawners. I did set a limit of 100 spawners in the script but if we ever had that many in a level it would be insane. I think the most we ever got up to was 8 or 10. The script spawner allows for a user to specify data directly on the spawner in our propagation tool. So the artist just enters the names of all the spawners for the roaches on the script spawner. For the artist that's it. That's all they have to do. The script itself contains two sections. The first creates a symbol array that we refer to as a group. So the script checks the data on the spawner I mentioned and if that data is specified it adds that roach spawner symbol name to the group. The function that does most of the work here is basically a while loop with a counter. The next section is where the real work is being done. Now that I have a group of symbols I use some functions to create some conditions for the script to check on those symbols every frame. I check the distance between the player and the roach spawner. I check to see if the roach spawner is within a specified radius from the center of the screen. and I check to see if the flashlight state is on. If all three conditions are satisfied it sets the boolean switch (Rootvar) on the roach spawner that has met all of the conditions to 1 and the roaches go scurrying away. The first time I saw it working I pooped a little.

So that's how all that works. It might sound expensive but it was all actually relatively cheap to run because it wasn't all that complex on the runtime side. Of course the more spawners we iterate over the more expensive it would become but it never got to that point and we were always mindful of that. The reason why I loved this whole setup so much was because of what it represents. It represents how flexible our tools have become to allow us to fully realize an effect without having to request any tool support. All the pieces to solve the puzzle and many others like it are at our disposal. While the end result is just some roaches, the concepts we learned and put into practice here have larger applications across other areas when creating effects and completing effects related tasks. This level of creative problem solving takes shape when the tools expose more access to the inner workings of the effects to the artist. I will say that we are super freaking lucky to have the support we do because if it weren't for Marshall exposing the root data to us we couldn't do this and a lot of other things. Also big thanks to Kurt and Nick for showing me cleaner and smarter ways to write the code for the scripts.

3 comments:

AnthonyB said...

Haha! Such a tiny effect, but so effective. I noticed them inside of Bill's basement myself. Great work. I've been playing around with Unity, and in a rail-gun arcade esq game, I'm spawning enemies as the player progresses with a similar logical setup as you seem to describe with the spawners. Their initial direction they run at is set to that axis of the spawner in the world. Its not too crazy complicated of a method to pull of a fantastic effect.

Unknown said...

At Pest Control abu dhabi , our pest control specialists understand how unsettling and unnerving the discovery of a pest infestation issue can be.
We specialize in safe, effective treatments for homes and businesses, ensuring your greatest assets are always protected while peace of mind is kept. A free inspection is all it takes.

contact us at 026650399
www.pestcontrolabudhabi.com

Anonymous said...

I really like this share,.
"3 Reasons Why"