There was an explosion of readership since
@Madiator2011 put this website on the
clearnet. And so now, since more people are reading me, I can branch out and talk about more things than just very important politically-charged philosophical discussions. I want to talk to you about stuff that I make, struggles that I have along the way, and thoughts about things other people do. Yes this website has a
reviews section full of my takes on various films and stuff. But I want more. And in this article I want to discuss the complexity of writing NPC characters for video games.
I'm developing a game called
Dani's Race, which is supposed to be a
GTA clone. A game where you can run around a city and cause all kinds of mayhem. And a humongous part of the experience of such a sandbox world simulator are the reactions from the in-game non-playable characters. If you steal a car, what will be the reaction of the driver? What will the police in the game do? What will other drivers do if you hit them on the road? All of this is a part of my daily problem-solving when working on Dani's Race.
Teaching cars drive is not an easy task, especially when you consider all of the real-life implications of such a technology, yet, for an immersive gaming experience, the cars on the road cannot be simple. They have to behave more or less in the same way a driver on the real road behaves.
I could have used a plethora of short-cuts and uninspired techniques, clever only with huge limitations of a game engine. I'm not saying that, for example,
Foggy Mound by Skindo Mimiz is a bad
Super Tux Kart addon. Because in this particular case, what he did was rather clever. The addons engine is limited in what you can do. And even thought there is a scripting language, using an animation instead to give life to the cars on the road is perfectly a valid approach. It is just a silly addon, silly unstoppable cars on the road, that repeat their loops over and over, aren't that big of a deal. Hell
even I used that same technique for my own Super Tux Kart addons.
But with Dani's Race, my personal expectations are way higher. I cannot just animate the cars to fly all over the town. They have to react to the player's mayhem. They have to be steal-able. They have to be breakable. And they have to have different levels of anger toward one another and towards the player.
How do you even animate a police chasing you in the game, which in the same time doesn't chase you if you are driving slowly and by the rules? You can't!
I had to sit down and write something that was inspired more by the self-driving cars and less by some animation or whatever. And I came up with a setup that works relatively well for normal NPC cars.
The engine has a function to send rays from any point in the space to any other point. If a ray like this is intercepted by geometry in the middle, the function will return data about this interception listing valuable information such as: the position of the point; the object that made the interception; the angle of the interception; the material of the very point of the object that caused the interception and so on and so forth.
I can use this data to determent various things about any given car on the road in the game. Basically I can shine those rays in various directions and observe the world of the game though them. And I don't need much. 6 rays that I am working with right now are plenty for this kind of machine vision. You need to see if there is anything in front, anything towards the right, anything towards the left. And have the same coverage again, but towards the ground to detect changes in terrain materials.
If there is a wall towards the right, I can tell the car to turn left. If the wall is on both sides, I can tell the car to calculate the distance to both walls and determent where to go, as to maximize all the distances. Meaning it could squeeze through some narrow pathways without hitting a wall.
Because the data also contains references to the objects that it sees, the car can sense the presence of the main character or a different car in front of it. And also something potentially different for different objects. And knowing the material is helpful to avoid driving off the road and avoid crossing the line in the middle of the road.
I made an invisible line which you don't collide with, in the center of all roads, which those rays can see. The line has a specific material, that the car knows to avoid only if it is from the left side of the car. But not if it is from the right of the car. Meaning if the car by some miraculous reason ended up on the wrong side of the road, it will be able to navigate back to the correct side.
All of this is rather simple stuff, even though it might sound complex. But Police is not that simple. To make police work, first they need to navigate the streets with the regular simple algorithm, the same one used for other cars, but then if the player does something extraordinary enough, warranting police intervention, then it should throw the algorithm out of the window and instead use a different, way angrier one, which is specifically optimized to give the player a tense time running away from an angry pursuit.
But what does it even mean to be optimized to give the player a tense time running away from an angry pursuit? What are the rules of the police game within the game? Like, okay, they are chasing you now. But why should you care? What will they do when they get to you? A the moment the only thing they are doing is trying to break your car until it explodes. I mean, it is a threat to some extend. But is it really police-like?
Comparing Dani's Race to, say Need For Speed Most Wanted, a game heavy with police presence that did quite a challenging police mechanic, Dani's Race is nowhere near as interesting. In Most Wanted, you have classes of different police types. You have the normal police that chases you normally. You have, what I assume is the FBI equivalent. They have faster cars and a much more capable drivers. There are heavy vehicles that the police is using to smash into you from the front. There are road blockers, tire poppers and other interesting stuff, with various techniques to get around all of this. In Most Wanted police has a goal. They are trying to stop your car. They will intentionally position themselves in-front of the player, to slow the player down. And if the player is too slow, too close to the police, for too long, it is game over, and an animation plays telling the player that the game character was busted.
This is already a challenge for Dani's Race, since I don't ever want to have unplayable cut scenes in the game. If the police captures Dani I should have some system where the police takes Dani by force, probably restricting the player's input. Maybe with an ability for the player to try to get away, but say the police can handcuff Dani to one of the policemen, and since he is heavier, Dani will not have a lot of chance to escape.
And then what? Should there be a whole thing, where Dani is taken into the car, brought through the city ( with self navigation of some kind ) to the police station and there, lets say, instructed to wait in the cell, for while Paps or some other character arrives to bail him out?
Or could the cell itself be somewhat penetrable? Maybe there is a hole or something that the police overlooked, since it was too small for adult inmates, but big enough for Dani, through which he can escape, to find his way out of the station.
Or even maybe through the station as a kind of small stealth mini-game. Which you will have to play each time you are busted. I mean that could be a great source of tension when dealing with police in any way in Dani's Race.
I can even go as far as to make the save file record that you are in the prison, to spawn you there when you start the game, if you still didn't escape.
Also the pursuit itself is rather complicated. At the moment the cars chasing you are trying to predict where you are going, and drive there. But that will be hard to modify into something where they are trying to stop you. How will that logic even work? I mean I can think of a few potentially plausible ways to implement it. They could, for example, sense in some way that you are about to smash into them, and start breaking at that point, to try to smash you into them. But then what?
Let's say they did stop you. How will the mechanics of capturing you work? How will the mechanics of escaping them from capturing you work? Also, since this is trying to be a family friendly game, I'm trying to avoid guns. And therefor, should the police use any force? Or are they literally just trying to grab you and push you into a car? That could be kind of interesting in a silly kind of cartoony way.
If I'm doing the whole police station thing, I have to introduce a crouching mechanic, a stealth mechanic and model the damn police station. Non of which I did so far. Maybe those are the things I need to focus on. Maybe my next stream will be dedicated to modeling of the police station. I guess it is an idea.
But what do you think? As a player... What are the kinds of things that you would like to see in Dani's Race? Please use the damn comment section in this website I made, and tell me your thoughts. Lets discuss this. Meanwhile...
Happy Hacking!!!