Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

FPSC Classic Scripts / Doom Style AI for FPSC

Author
Message
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 4th Jan 2019 20:57 Edited at: 8th Jan 2019 09:32
Happy New Year, or near enough.

Over the holidays I've had some free time to finally learn FPI scripting and set out to solve the one problem that has plagued FPSC since the very beginning: Pathfinding.
Over 10 years too late for it to be relevant but whatever

I looked for the simplest solution for non dark ai scripting and settled on the Doom engine solution: Move towards the player, if you can't move towards the player then turn in a random direction and move there

After I got this kind of working I decided to recreate the basic routine of Doom's AI in FPI to see if it was possible.
First I had to set up a tic system as AI in Doom was checked every frame at 35fps, as well as the pseudo random number generator.
Then I had to sort out the alerting from sight, sound noise and touch, including the ability for other monsters to alert each other.
Then I had to sort out the movement routine, including a somewhat accurate recreation of the checks done to perform attacks.
Then there was the redirection and 'pathfinding', which I chose to make using raycast to detect wall collisions as I couldn't figure out how to detect a character's momentum.
Finally the was the painstates that pause the enemy AI semi randomly while taking damage.
After that I decided to recreate the attack patterns of some of the monsters.

This was somewhat simple but I kept running into inexplicable animation problems and needed to tweak some things to work better.
I assume my scripting style is trashy and messy but I tried to stay loyal to the source material as closely as I could as someone only vaguely familiar with both C and FPI
I tried to annotate it the best I could.




Hopefully these scripts allow people to create simple doom clones in the engine. Use these with projectiles without slash damage and it's quite engaging.
Really this should have been the first thing anyone should have tried to make in the engine. The good old 'Can it Run Doom?' question.
This was a project in nostalgia for 2 of the most influential things to me, as well as a test of the limitations of this approachable but infamously limited tool for amateur FPS designers.
I wanted to find where the FPI scripting succeeded and failed by emulating the AI of a simple and classic game written in a higher level language (C)
I found inexplicable problems, such as the slow ticrate and inconsistent P_RANDOM checks as well problems with animations that worked perfectly fine in stock scripts.
I thought about trying to make it using only V1.0 scripting however I knew that would not be possible at all so I chose to use the current standard of scripting to see how effective it ended up.


So here's the end result:

VERSION 1 DOWNLOAD
VERSION 2 DOWNLOAD
VERSION 3 DOWNLOAD


Appear Scripts
Variable are used to define the AI's attributes and animations, allowing there to be only one Main script that is neccessary.
By changing these variables you can affect character speed, strength and such in a reliable manner.
Since a lot of the attack behaviours are defined by animation timing it might be useful to select useful animations for such things.
Here are some default values. They're based on Doom engine values but get adjusted to FPSC scale in the mainscript (speed 8 translate to 100)


Main Script: MainAI.fpi
This handles all movement and decision making of the monsters. All monsters should use this or a variant as their main AI loop.
They do not use waypoints for anything as that was a Quake feature.
Enemies alert, move, attack and redirect with the same method as the 1993 engine. They can open closed doors (and maybe switches?)
Sadly infighting is not possible as the target mechanics of FPSC are not reliable for targeting anything other than players.
It uses a tic system to emulate the pace of the original AI.
If you want an ambient sound put one in your character's sound1 field. It will randomly play while the AI moves.

These lines have sounds you can change.
:state=2:sound=audiobank\voices\monster\spawn.wav
:state=101:setframe=%painstate,sound=audiobank\voices\monster\hurt1.wav,state=111,bloodspurt=1

If you want the AI to respond faster or attack more you can change the line
:varequal=gametic 0:setvar=gametic 14 ;//29 seems really slow, try half instead
If you lower that value it updates the AI more often (this will cause the AI to move less far however as the movecount will decrease faster, but as a result the likeliness of attacking is higher
As you can see I lowered it be default as the tic system seems oddly slow.

If you want the AI to move for longer distance change the line
:state=51:setvar=flags 0,setvarrnd=movecount 15,state=4 ;//go to A_Chase with up to 15 steps to make
As you can see this by default chooses a random value for the movecount between 0 and 15. (keep in mind AI can only attack while movecount is less than 1)

7 Shoot Scripts
These affect how an AI attacks and are roughly based on the attacks found in the original games.
Projectiles and guns should use different scripts because I intended to make the guns have delayed aiming, however that is not possible in FPSC (though it is possible for projectiles?). The gun scripts set their weapon accuracy to 20% instead.
Damage is randomised between 60-140% to emulate the damage variance in the classic games

projectilemelee
This is the basic projectile attack.
It plays a throwing animation and fires halfway through. However if you're close it will switch to melee instead. However if you initiate it in melee range and move further it will switch to the projectile attack.
This emulates the behaviour of the Imp

projectilemeleemiss
This is the basic attack however it locks the AI into melee or projectile attacks.
If the player is in melee range it moves to the melee state and will do a full melee animation. This can be dodged.
If the player is too far away it chooses to do a projectile attack.
This emulates the behaviour of Revenant (though not really as the revenant would charge at the player from a certain distance)

projectileburst
This is a rapid fire barrage of 3 rockets. It shoots one rocket every .75 second, reloading and reaiming between shots.
If the player is in melee range it will melee attack them, this can be dodged.
It loops the firing animation, so choose one that looks good.
Change the shotsremaining 3 value to chance the volume of the barrage
Change the etimergreater=750 value to change the rate of fire
This emulates the behaviour of the Cyberdemon but adds melee

projectilespread
This fires 3 pairs of projectiles every .5 second in a spread pattern. First attack fires of (the AI's) right, the second straight forward and the final to their left.
If the player is in melee range it will melee attack them, this can be dodged.
It loops the firing animation, so choose one that looks good.
This one was challenging to do but works really well. It technically shoots 1 at a time but the time difference between the firing is so small it's not noticeable (aside from the phasing of 2 fire sounds).
Change the rotatey=(+ or -)5 value to get a bigger or smaller spread. Try to keep them to the same value or else it will mess with the spread
This emulates the behavious of the Mancubus but adds melee

semiautomelee
This is for single shot attacks, preferably with guns.
The AI will play it's attack animation before firing to give you a brief moment to get into cover.
Since the animation plays before firing this could be a reload or whatever.
This emulates the behaviour of pistol and shotgun zombies

fullautomelee
This is for continually firing attacks such as miniguns. The AI behaves the same as the semi auto attack however it will not stop shooting until the player is out of sight, dead or the gun is empty.
The firing animation loops during firing.
Change the etimergreater=125 to affect the rate of fire
This emulates the behaviour of the Chaingun zombie

chargemelee
This is for charging enemies. It will very quickly run to the player and if it hits them it causes damage. If it misses it keeps moving for a while. It uses setentityspeed=x to do this.
This script is very buggy and I could not find a solution for it. The enemy stops when reaching the target sometimes, sometimes it will not stop moving and will go straight through a wall despite constant raycasts to detect collision.
Also it resets the movement speed to 100 after a charge so don't bother changing the entity's movement speed. This is because it used movetotarget so that it works for flying monsters, this ignores floors (and other collision it seems)
Similarly my attempts with flying monsters were really unsuccessful so I never bothered to add real support for them.

I did want to make death scripts that would allow resurrection with an archvile style healer, however there is no way for that to work as entities cannot check a another's health or other variables.
However I could do this with activation checks, similar to how door opening works?
Similarly I could not think of a way to create a simple gibbing effect by spawning a ton of gore pieces. Sad.


The problems I've got so far...
Enemies can see you through walls it seems. I think that's an engine problem.
The tic system seems slow but I'm not sure why. I assume the script system updates every millisecond like the timers but it seems off.
I can't manage to make it detect if the AI is blocked by a dynamic entity as the raycast only hits static geometry. Using anywithin=x only results in it constantly detecting something (most likely itself) so that's useless.
Some walls, particularly those on the outside of a map will not be detected by raycasts and will make AI hopelessly walk into them for a while.


While these scripts might not be useful for everyone I hope that it provides a useful resource for the small community remaining here. Even as a memoriam to the engine, its abilities and limits.
If you have any problems please post them in the thread. And if you have any ideas for solutions or fixes to problems please post them.
If something compiles on the first try. Something is terribly wrong.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 4th Jan 2019 21:06
Interesting... and thanks for the download. I'll check these out because like you say, always been an issue.
You wouldn't happen to have any videos of these in action, would you?
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 4th Jan 2019 21:51 Edited at: 4th Jan 2019 21:52
Yeah here's some enemies in a scene.
If something compiles on the first try. Something is terribly wrong.
ncmako
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 4th Jan 2019 22:31
@ uzi idiot Terrific work Thank you for putting this together.
Looks really good in the video. I look at some of the variables you setup... and Wow! You put a lot of
effort/work into this ! Downloaded and will test out here shortly. Will let you know.
Thank you again
My games never have bugs. They just develop random features..
Lots and lots of random features...
Location: You know that space between a dresser and the floor ? Yeah, that's where
seppgirty
FPSC Developer
14
Years of Service
User Offline
Joined: 3rd Jul 2009
Location: pittsburgh, pa.
Posted: 4th Jan 2019 23:05
This is very interesting UZI. TOns of work went into these scripts. It's never to late to work on fpsc.
gamer, lover, filmmaker
Kaelyss
5
Years of Service
User Offline
Joined: 20th Dec 2018
Playing: Doom II
Posted: 5th Jan 2019 04:25 Edited at: 5th Jan 2019 04:26
Terrific, I've often wondered if replicating a somewhat Doom-ish feel and gameplay in FPSC was possible. Apparently it is !

uzi idiot wrote: "
fullautomelee
This is for continually firing attacks such as miniguns. The AI behaves the same as the semi auto attack however it will not stop shooting until the player is out of sight, dead or the gun is empty."


Sounds interesting, I have a few ideas about how to use this one, like on a HMG operator or even a stationary sentry gun.
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 5th Jan 2019 15:07
Ah so I've been using variables wrong the whole time. I forgot about %
So I'm updating it to use an appear script to get the variables so that you just need the one Main script (apart from changing sounds)
If something compiles on the first try. Something is terribly wrong.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 5th Jan 2019 21:03
Great. Thanks for scripts and videos. It looks great. I'll watch for the update.
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 5th Jan 2019 21:37
OKAY Version 2
Gotta love it when you find a million things wrong the moment you release something.

VERSION 2 DOWNLOAD

Changes:
All AI attributes, such as health, speed, painchance etc are controlled by variables in the Appear script
Animations are controlled by variables in the Appear script too.
The ambient search sound can now be assigned in the sound1 field of the entity
ProjectileMelee is now the only attack script that lets an AI switch between melee and projectile halfway through an attack (note: if you're using this for a melee only character, assign a missilestate value for the animation)
AI can more reliably opens doors.
Pain States are fixed
Full Auto script is fully functional
Damage randomisation seems functional

Here's an example of the variables in the appear script (a dozen have been included based on the original game's enemy types)


If something compiles on the first try. Something is terribly wrong.
BlackFox
FPSC Master
15
Years of Service
User Offline
Joined: 5th May 2008
Location: Knight to Queens Bishop 3
Posted: 5th Jan 2019 21:39
Quote: "Ah so I've been using variables wrong the whole time. I forgot about % "


Yes, that variable gets everyone at least once or twice

Nice work on these. They are a welcomed addition to the script arsenal.
There\'s no problem that can\'t be solved without applying a little scripting.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 6th Jan 2019 02:39
Thanks again uzi. Notice how I stopped short of calling you idiot. It's just the way I am. And Yellow doesn't like it when I'm rude.

seppgirty
FPSC Developer
14
Years of Service
User Offline
Joined: 3rd Jul 2009
Location: pittsburgh, pa.
Posted: 6th Jan 2019 15:56
Thanks again UZI. These are great. Nice to see some of the old crew stopping by.
gamer, lover, filmmaker
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 8th Jan 2019 01:42 Edited at: 8th Jan 2019 01:44
I've cracked how to calculate a character's velocity. I think I might be finished with this soon.

If you're wondering how, here's the test script I made. It makes a character walk forward, checking it's velocity every second, if the velocity is 0 then it turns 180 degrees

If something compiles on the first try. Something is terribly wrong.
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 8th Jan 2019 09:31
Here's Version 3.

VERSION 3 DOWNLOAD

Changes:
AI now checks it's velocity every tic as well as a raycast, this stops AI from getting stuck on ledges
Enemy presets have had their speeds adjusted to take into account frame times of the state system used
Enemies check if the player is too close and turns around to avoid pushing them out of the map
Pain States are added to the shoot scripts, allowing you to cancel attacks
AI have their raycast distance reduced to stop them from getting stuck in in narrow hallways
If something compiles on the first try. Something is terribly wrong.
ncmako
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 8th Jan 2019 11:32
Uzi " V3" I like your approach on this using the entities positions. The one I don't know is
varmul=x ? Is it mulvar=x by chance ? ( a typo ? )
My games never have bugs. They just develop random features..
Lots and lots of random features...
Location: You know that space between a dresser and the floor ? Yeah, that's where
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 8th Jan 2019 11:51
Ooooh.
I was wondering why that wasn't working
If something compiles on the first try. Something is terribly wrong.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 8th Jan 2019 13:59
@uzi or ncmaco
Have you noticed any/much taxing on the engine with multiple AI using this?
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 8th Jan 2019 14:09
I assume it's much more taxing on the engine than the stock AI scripts. A single NPC uses 3 bars or so on the performance metric thing for me.
If something compiles on the first try. Something is terribly wrong.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 8th Jan 2019 16:51
Yes, compared to the stock AI scripts is what I meant. "much more " is what I was afraid of, but as usual, we'll have to adjust where needed.
That said, if it's logical and consistent, that will be a huge plus.
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 9th Jan 2019 16:53
I don't know what the performance cost of certain things is in the scripting system but the amount of variables and constant checks the scripts have to do probably isn't cheap.
If something compiles on the first try. Something is terribly wrong.
ncmako
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 10th Jan 2019 11:20
@ xplosys
Quote: "Have you noticed any/much taxing on the engine"

Yes, a little. Have been trying out different setups with the scripts to see what I can achieve.
Using about 3 or 4 npc's I still get a steady frame rate in the 40's. Not bad, considering with
what the script has to run. I'm still exploring the scripts and how to use them... all in all, these
are great and work as intended. My characters navigate around all objects/entities that I've used so far



My games never have bugs. They just develop random features..
Lots and lots of random features...
Location: You know that space between a dresser and the floor ? Yeah, that's where
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 10th Jan 2019 13:07
Quote: "My characters navigate around all objects/entities that I've used so far"

Thanks for checking it out on your end and reporting back.

FPSC now has what DOOM had in 1992!

But seriously, for me the issue has always been the AI. After putting together a decent level, its always been discouraging to try to make semi-intelligent AI navigate and work in it. If they're not running into walls and acting like drunken idiots, they're just standing around like government workers on the clock. It's time to go back to some saved levels and try again.

Thanks uzi.



ncmako
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location: Hendersonville,NC
Posted: 10th Jan 2019 22:37
Quote: " just standing around like government workers on the clock "

Ncmako < ---- Government worker how just stands around while on the clock
My games never have bugs. They just develop random features..
Lots and lots of random features...
Location: You know that space between a dresser and the floor ? Yeah, that's where
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 11th Jan 2019 02:34
I only wish there was a more optimised way to do this kind of thing. I'm trying out a version that doesn't use raycasts and instead just checks the momentum but I'm not sure if that's any better performance wise.
I don't actually know how FPI works, I've skim read some of the source code but I don't know how intensive it is. Does the code get compiled down into bark basic? does it get compiled even further (I'm assuming dark basic is based upon C++ here)

Either way I'm happy that I at least got it working, I'm just sad that no one did it sooner, especially considering as xplosys said it has always been a problem. I just wanted to see if I could use the simplest and most primitive solution.
Always remember to ask "but can it run doom?"

If something compiles on the first try. Something is terribly wrong.
s4real
VIP Member
17
Years of Service
User Offline
Joined: 22nd Jul 2006
Location:
Posted: 16th Jan 2019 23:57
Nice work on these will check them out

Thanks for sharing best s4real
Amd fx4100,6gb ram,geforce 450
ScooT9
7
Years of Service
User Offline
Joined: 29th Mar 2017
Playing: Half-Life: WAR
Posted: 28th Jan 2019 12:46
I have tested the ai, i'm using the semiautomelee script, the enemies don't notice me even though i'm right in front of them, they just walk in random directions, but even if an enemy notices me, it plays a reload animation and it shoots once, then it continues to walk for about a couple million years.
Is this a feature or just a bug, also, the "reload animation" before shooting just makes the game really easy, can you make a version without that reload animation?
hi, i'm a random guy who's making random games with random game engines for random reasons
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 28th Jan 2019 19:52
That's how it works yes, if you want to increase the fire rate or change the animations the instructions are in the OP
If something compiles on the first try. Something is terribly wrong.
ScooT9
7
Years of Service
User Offline
Joined: 29th Mar 2017
Playing: Half-Life: WAR
Posted: 28th Jan 2019 21:26
thanks for the answer, but is it possible to make the enemy not reload at all and just shoot?
hi, i'm a random guy who's making random games with random game engines for random reasons
uzi idiot
Valued Member
14
Years of Service
User Offline
Joined: 27th Dec 2009
Location: Who Knows?
Posted: 29th Jan 2019 07:45
Yeah find the appear script and set missilestate to 1, this makes it use the idle animation before firing
If something compiles on the first try. Something is terribly wrong.
Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 8th Feb 2019 00:09 Edited at: 8th Feb 2019 00:11
Thanks for this, Uzi idiot. I'm not like xplosys not calling you an idiot because I also am an Uzi idiot. The weapon that I used in 'Nam was an uzi along with a couple of other types of weapons.

I see why you have the "Valued Member" badge. This is a valuable addition.
THEORY - you know everything but nothing works. PRACTICE - when everything works but don't know why.
For me, theory and practice are combined: nothing works and I don't know why.
Mriganka
9
Years of Service
User Offline
Joined: 16th Jun 2014
Location: Virtuality
Posted: 2nd Apr 2019 17:16
Damn! Nice job man uzi. This would help us so much!

Login to post a reply

Server time is: 2024-04-19 13:16:47
Your offset time is: 2024-04-19 13:16:47