Product Chat / Ai Collision Off?

Author
Message
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 14th Oct 2019 13:58
I know we can use CollisionOff(e) and that lets the ai pass though objects.

But is there a way to stop the ai from avoiding each other?

I want the ai to run into/though eachother b/c with CollisionOff(e) they can.
But it's coded somewhere for them to avoid eachother.

Just need to know what script or file that bit is in so I can find and edit
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Oct 2019 17:29 Edited at: 14th Oct 2019 18:05
hmm my AI quite happily walk into each other when following waypoints... which behaviour are they in when they are "avoiding" each other?
and which AI/characters are you using?
it's a bit of a difficult one to test as it's rare for the AI to be in the same place unless they are on the same path - and as i say, they don't avoid each other for me


anyway the code to avoid stuff is in module_combatcore.lua
function module_combatcore.moveandavoid(e,AIObjNo,PlayerDist,MoveType,x,y,z,stopstate)
this part
if g_Entity[e]['avoid'] == 2 or (g_Entity[e]['avoid'] == 1 and stopstate ~= ai_state_startpatrol) then
ai_bot_substate[e] = math.random(1,2)
if ai_bot_substate[e] == 1 then
tAvoidAngle = AIGetEntityAngleY(AIObjNo)-95
else
tAvoidAngle = AIGetEntityAngleY(AIObjNo)+95
end
tAvoidAngle = (tAvoidAngle / 360.0) * 6.28
tAvoidX = GetEntityPositionX(e) + (math.sin(tAvoidAngle) * 30)
tAvoidZ = GetEntityPositionZ(e) + (math.cos(tAvoidAngle) * 30)
AIEntityGoToPosition(AIObjNo,tAvoidX,GetEntityPositionY(e),tAvoidZ)
StartTimer(e)
end
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 14th Oct 2019 18:39 Edited at: 14th Oct 2019 19:52
I just tested this with way points also.

I want them to walk through each other. Like they are not there. But even if you turn off physics/CollisionOff(e),
they will still bump into each other.

I would like to remove that bit so that when I have lots of ai running around they dont bump into each other in door ways.

When I said avoid, prob not the best word used. But I ment avoid the point that another ai was at. But that was b/c I was testing with 1 standing still and the other could not get to the cords under the one that was standing
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Oct 2019 20:12 Edited at: 14th Oct 2019 20:18
i know it's not what you wanted but i was curious if i could add some extra avoidance to the AI - this was the result... not perfect but considering there's a lot of stock AI logic to fight against i think it works pretty well
though they do double back a bit too much but i tried to keep the method as fast as possible so as not to eat all the fps, i'm sure with some more complicated checks in there they could reduce the turn rate right down but this is way faster than the first method i did which looped through a linear group of angles and distances to find the first gap - perhaps somewhere in the middle would be best

or for a better comparison to the first video here it is with just a patrol route and more AI
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 14th Oct 2019 23:39
I think something like this will work for me. I might play around with a couple ideas.
have ai wait in lines if more then 1 are trying to go though the door. I made my on waypoints so checking this would be easy I think.
I could have a in and out door to stop some of the bottle neck later.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Oct 2019 00:09
@smallg : the AI bar in your videos shows up just how poorly optimised the scripts are.
Been there, done that, got all the T-Shirts!
PM
benjiboy
7
Years of Service
User Offline
Joined: 24th Mar 2017
Location: In the depths of rural Norfolk
Posted: 15th Oct 2019 06:00
So how can I get a'hold of your improved avoidance smallg?
You can't teach an old dog.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Oct 2019 08:03
Quote: "@smallg : the AI bar in your videos shows up just how poorly optimised the scripts are."

Yes but not sure if that was jumping as much before my code or not, I know raycasting is taxing but I only do 1 per character on a delay so it doesn't drop the FPS but I didn't get time to test it fully yet

Quote: "So how can I get a'hold of your improved avoidance smallg?"

Unfortunately my pc is out of action for now due to a roof leak, if I find somewhere else to set it up I'll post the script, otherwise it'll take a while
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Oct 2019 18:12
ok i managed to get GG to run on my laptop - already a miracle in it's own right
rewrote the general script (as i don't have access to my first version), this one follows a similar but slightly different approach - it still won't fix any such occasions as someone standing on the spot the AI want to path to but it will help them avoid each other
i didn't notice any drop in FPS so should be good for testing, let me know if you have any issues
p.s. you should keep them in a "smallg" folder inside the scriptbank and assign the new ai_soldier.lua script from there (so it won't get overwritten from updates)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Oct 2019 00:53 Edited at: 18th Oct 2019 03:21
@smallg
I've taken the liberty of taking the combatcore you posted and hacking it to give way better performance, am about half way through it but came across this bit and thought you may be able to work out what it is trying to achieve:


Pay particular attention to the ????? bits cos they look dodgy to me.


Attached the changes so far, haven't tested it yet and don't expect it to work, I'll test/debug it tomorrow (in between Spitfire stuff ).

In theory it should run a lot better that the original but the real difference will come when all the modules are treated likewise and I can eradicate ALL the global variables.

Can you post the fpm of your test level?
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Oct 2019 09:11 Edited at: 18th Oct 2019 09:32
That code is used to stop the AI trying to stand on top of each other when trying to melee the player - they sort of form a circle around you but of course if there's too many they will still pile up.

The bit you marked out is similar to the code I used to avoid each other, it works by getting an offset based on a given angle - in this case it uses their 'e' so most angles will be different (so a character of entity 1 would be looking to place himself at an offset of 50units 1° in front of the player... Therefore entity 180 would try to place himself behind the player.
only works on a flat (2D) circle but as they're limited by the terrain/player height anyway it's fine
also remember this code is only used if there's more than 1 AI in close range to the player and the AI in question is not already in melee range... otherwise entity 180 would continuously try to move behind the player while the player is trying to aim at him

My code follows the same logic except I try to work out the obstacles velocity so the character attempts to move behind the obstacle (so as to avoid walking into their path) and (most) can be found in the moveandavoid function.. I'll post the code snippet (though it won't run with just that) and the fpm (just a bunch of AI on the same path)

edit;
my code is the second half of this block (found in module_combatcore.moveandavoid())

plus a little bit extra to work out the velocity each frame at the top of the same function

the rest of the file is stock code (plus any set up and file reference changes)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Oct 2019 16:51
I'm getting a weird error with this.

I've altered the code (see attached) quite a bit but I'm getting a spurious error.


At the point the error occurs I've tried putting an 'if nil' check around it but it doesn't make any difference!

I do have about 100 zombies on the map though.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Oct 2019 19:08
hmm i'm not getting any nil error, it should have nil checks already but maybe adding some for nex/nez will help? (i don't see how those values could ever be nil but i don't see any other values that aren't checked so.. )
local nex = GetEntityPositionX( obsE )
local nez = GetEntityPositionZ( obsE )
--if nex == nil then nex = 0 end
--if nez == nil then nez = 0 end
i do notice the AI can briefly fly off into space if they walk over each other though, kinda funny but i guess this is just a physics capsule reaction, i think that was happening before, probably just more noticeable with my low frame rate as it takes longer to correct itself.

so i ran a comparison with the stock AI;
using the same set up (13 active AI, 2 obstacle AI, 1 path - fpms in attachments)
i get around 12fps and an AI bar of around 45 ~ 65 with stock AI
i get around 8fps and an AI bar of 65 ~ 75 with your new script
results from my laptop but still a pretty noticeable drop, raycasting is either way too expensive or there's something wrong, will look into it more when i get my PC back

other notes;
is the delay on the node points normal behaviour now? looks weird to see them sort of get stuck at the end of waypoints etc - was doing this with the stock AI before i changed anything, just curious if you get that too?

i also hate the way the AI can sense you're looking at them regardless of distance... that definitely needs some extra checks to ensure view distance etc is accounted for.

thanks for taking this further, it's definitely an area that needed improvement but i'm not doing much testing / editing in GG as it's not fun to work with such low frame rates
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Oct 2019 20:31 Edited at: 18th Oct 2019 20:32




Well that has me stumped!

Aha, just realised, it is the return value that is nil!
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 18th Oct 2019 21:51
tested "ai avoiding each other.fpm" not nil error, all works ok, well, from time to time someone gets the jetpack, and it's quite funny.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Oct 2019 23:07 Edited at: 18th Oct 2019 23:08


Oops, think I may have broken something.
Been there, done that, got all the T-Shirts!
PM
osiem80
5
Years of Service
User Offline
Joined: 24th Jan 2019
Location: Poland
Posted: 19th Oct 2019 01:18 Edited at: 19th Oct 2019 01:19
looks like one of them lost somethink and the others help him search
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Oct 2019 08:34
Quote: "looks like one of them lost somethink and the others help him search "

Lol, probably dropped his contact lens if normal enemy AI accuracy is anything to go by :p

I think the stock AI would work a lot better if the commands being used were actually working as intended -
I.e.
- AIGoToPosition() only takes 2 coords but it is nearly always used with 3....
- AISetRotationYSlowly() doesn't appear to work (or perhaps it works on the invisible AI, it's hard to tell, either way it does not work the way it is intended to in the script).

@amen, is the DarkAI exposed in the source code? Do you know if it is possible to get the real AI's location (the 'obj') rather than the entity's?
It would solve the weird path finding and the jetpacking AI as we wouldn't need to force the obj to the entity but do it the other way around - you want your visuals to match the physics, not the way we have it now (I'm sure Lee had his reasons for doing it the way it is though so probably not possible)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 10:03 Edited at: 19th Oct 2019 10:14
Hmm, might be something to look into if I get a moment.

The main problem is that there is the concept of a 'ghost' object (not sure I fully understand how it is implemented) for characters then there is the location of the current animation frame, which may not be where the character capsule is and the entity position.

I'm not quite sure what the GetEntityPosition functions return and how that differs from g_Entity[ e ] values but if you want to get the actual 'object' location (i.e. the current location of the characters physics capsule) you can use GetObjectPosAng( objId ).

Btw, when used with X,Y,Z values the AIEntityGoToPosition function does the following:


Your guess is as good as mine as to what that is all about, something to do with floor zones?
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 19th Oct 2019 10:30
Quote: "The main problem is that there is the concept of a 'ghost' object (not sure I fully understand how it is implemented) for characters then there is the location of the current animation frame, which may not be where the character capsule is and the entity position"

Same happens with objects, remember having that issue with the bulb animated and the light following the bulb waving movement.

ControlDynamicCharacterController() -- controls the physics capsule of the player

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 10:41
@3com - Those two functions return the corners of a box collision shape for simple box collisionmode entities, not sure what they would return for a character as it doesn't have a box shape.

Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 19th Oct 2019 11:03
Yes, we need something such as ControlDynamicCharacterController(), since we are just talking about collision between chars, and does not char againts objects.

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Oct 2019 16:25
hmm yep i stand corrected, using 3 points in GoToPos does work - i swear it didn't when i tested it before but perhaps that was just something else in the AI.
SetRotationYSlowly() only partly works though, it doesn't follow the path or update the path so leaves the AI very open to getting stuck

i tried reversing the logic but the AI doesn't move.. seems the current approach is the best approach anyway as my test is not currently desyncing the AI with the visuals so i'll test more to see what does cause it
the 3 approaches can be seen in the attached files
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Oct 2019 16:58
or this version;
you should see character 1 follows the waypoints fine - only thing "odd" in his script is a slightly higher modulated speed
character 2 may get stuck (only happened rarely for me) while patroling - he has higher modulated speed plus a higher moveforward speed
character 3 should get stuck quickly - he has the slow y rotation
if you press E you can toggle character 2 to try reach the player - i purposely added a rotatetoplayer command in with the normal movement commands and you will notice he can get blocked by the boxes very easily too when in that state
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 17:53 Edited at: 19th Oct 2019 17:55






Looks worse the more AI you add but it looks to me like the avoidance angle is a bit too large, also this approach works fine when only two AI are on a collision course but breaks down if there are more than that.

Oh and I have changed the files a lot!
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 17:57
O and I have only tested the patrol functionality so far, I may have broken some other things.

Performance is way better though.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 19:52


Is that what it is supposed to look like?

I've attached all the ai scripts I've updated to, hopefully, perform a bit better.
The main problem is that Lee put all the ai lists in global.lua as global lists when for best performance they need to be located in the core module as locals, in fact I may turn the modules into proper Lua mudules (like utillib etc) and just have a single global g_aiList variable with all the other values as fields within it. For example aiList[ e ].bot_state or aiList[ e ].bot_angryhurt etc.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 20:16
@smallg - serious question, would you like to join forces to 'fix' the ai modules? It is way too much for one person to take on.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Oct 2019 20:55
nice job, your AI bar is way lower now
Quote: "Is that what it is supposed to look like? "

yep, for me the guy on the right gets stuck very quickly though (if you turn on debug visuals you will see why - he doesn't follow the path)
and if you tap E when the middle guy is furthest away from the player you should see him run into the boxes and get stuck trying to reach the player.

i was just testing the differences in the commands used by the stock AI, seeing if i could isolate the reason for them getting stuck on obstacles and if there's any correlation to the times when they desync and get sent flying into space etc - as the core AI is actually pretty good about avoiding (static) obstacles but there's some dodgy logic in there that makes it worse - so if we find the reason we can fix it and know what to avoid when editing further.
all i really found so far is that any messing with the rotation is not updated in the pathing (this is very clear if you watch with the debug slider on) so it may need some internal tweaks or maybe just a better order of execution in the scripts can fix it.

Quote: "@smallg - serious question, would you like to join forces to 'fix' the ai modules? It is way too much for one person to take on."

looks like you've already done a huge improvement to the speed of it, i'll definitely use your new scripts to improve the avoidance further and sure but i can't do much til i get my PC back, this crappy laptop is not fun to work on - it's only meant for watching tv
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 19th Oct 2019 21:09 Edited at: 20th Oct 2019 12:01
If you can do that how about not getting stuck in walls
I try to make my areas big so they have plenty of room, Nice wide doorways and the AI works better but far from perfect. To narrow and they clog up ( probably why they can walk through each other in the first place )
Better seen from this view …This is also using the ebe.

The only person ever to get all his work done by "Friday" was Robinson Crusoe..
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Oct 2019 22:57
GG is a never ending giver of surprises.

The current AI modules use global constants for the bot_states, which is bad for performance so my first attempt to improve performance was to replace all references to the global constants with strings (the actual ai_bot_state list is still global though) and this is the result:



Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Oct 2019 12:20
The latest if anyone wants to play around with it. *** warning I've changed global.lua for this!

If anyone works out why the AI are moving so fast before I do please let me know.

This is a major re-write of the modules (edging towards being 'proper' modules) but functionally they *should* be the same as the standard ones.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 20th Oct 2019 13:20
Quote: "If anyone works out why the AI are moving so fast before I do please let me know"

It looks like


rather than


might help.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 20th Oct 2019 13:31
I gave it a try using the same map above …
Enemy see me and shoot but there seems to be a long pause before actually chasing me ( then its very fast )
I get this error about 3 out of 5 times trying my level ..
I can do a video if it would help ..



The only person ever to get all his work done by "Friday" was Robinson Crusoe..

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Oct 2019 13:48 Edited at: 20th Oct 2019 18:10


Fixed a few bugs, including the one shown by synchromesh (I hope).

Btw, some behaviours may be a bit buggy as I've only ironed out bugs in the bits relating to patrolling so far.

Edited to add another bug fix, they will attack now. (in module_combatcore.lua)
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM

Login to post a reply

Server time is: 2024-03-29 01:45:20
Your offset time is: 2024-03-29 01:45:20