[icon ] blenderdumbass . org [icon scene] Articles

The Challenge of Writing NPC Characters for Games

[avatar]  Blender Dumbass

December 09, 2024

👁 121

https://lm.madiator.cloud/ : 👁 2
https://blenderdumbass.org/ : 👁 2
https://blog.madiator.com/ : 👁 2
https://download.tuxfamily.org/ : 👁 1
https://lemmygrad.ml/ : 👁 1
https://mastodon.online/ : 👁 1
https://mastodon.social/ : 👁 3

#DanisRace #MoriasRace #GameDev #FreeSoftware #Gnu #Linux #OpenSource #GtaClone #Programming #UPBGE #blender3d

License:
Creative Commons Attribution Share-Alike
Audio Version





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.


[embedded image]


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.


[embedded image]


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.


[embedded image]


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!!!





Subscribe RSS
[icon link] Author
[icon link] Website
Share on Mastodon









[avatar]  Madiator2011 c:0


...from blog.madiator.com

Who cares?

Description

[icon internet] View Full Reply [icon send] Reply



[icon reviews]An American Pickle

  Unread  

[thumbnail]

[avatar]  Blender Dumbass

👁 38 💬 0



Seth Rogen is an interesting filmmaker. Sometimes I feel like he is a manifestation of me when I will be older. But to be honest it's just wishful thinking. Wait for my review on The Fablemans to understand why. Seth Rogen is Jewish. He looks kind of big. Sometimes directs movies. He has Ukrainian ancestry. And he is a fighter for Freedom. Basically me. No... Wishful thinking. I don't think I will get anywhere near as popular. Basically Spielberg. Yeah that's better.


[icon petitions]Release: Dani's Race v25-09-24

  Unread  

[thumbnail]


27 / 30 Signatures

[avatar]  Blender Dumbass

👁 88 💬 0



Dani's Race version 25-09-24


#DanisRace #MoriasRace #Game #UPBGE #blender3d #project #petition #release


[icon articles]How to Make a Blog Like Mine Using BDServer Software?

  Unread  

[thumbnail]

[avatar]  Blender Dumbass

👁 50 💬 1



I want to document the way you might have a possibility to use the same software to make a similar website. @Madiator2011 already done that with blog.madiator.com. Lets go over: where you get the code, how do you set it up, how do you publish, how do you manage accounts, and most importantly, how do you modify everything, so it will look like your own thing.


#blog #blogging #webdev #website #python #programming #BDServer


[icon articles]Dumb Phones

  Unread  

[thumbnail]

[avatar]  Blender Dumbass

👁 50 💬 1



"You know they are listening to us this very moment?" - said Jake to Tom on a party one night. "What are you talking about?" - Tom was obviously confused. So Jake had to continue - "You know the Facebook app and the Google app on your phone is constantly recording what we have to say to each other, forming an opinions on us. They claim it's for advertising. But they can use it for anything they want. You know?". Tom looked at Jake with a slight smile. He knew he had a very good comeback. After a short pause Tom said - "I use a dumb phone." - and went into the party. But Jake didn't stop feeling bad. Jake didn't use no phone at all.


[icon reviews]The Killer

  Unread  

[thumbnail]

[avatar]  Blender Dumbass

👁 36 💬 0



I miss the times when you could see a David Fincher movie in the cinema. The last time he made a true cinema picture was almost 10 years ago in 2014. Since then he fully embraced the DRM filled streaming dis-service models. And his latest film The Killer is a straight to Netflix production. And it seems like he himself feels a bit off about it. Because if we take the character as a proxy for Fincher himself. This character is complex in how much he tries to justify himself being a terrible person.


[icon codeberg] Powered with BDServer [icon analytics] Analytics [icon mastodon] Mastodon [icon peertube] PeerTube [icon element] Matrix
[icon user] Login