AI collisions

Blitz3D Forums/Blitz3D Programming/AI collisions

Tyler(Posted 2006) [#1]
In my little game demo, I have several goblins that move about and follow the player when he comes into range, and they're all able to stop within a certain distance of the player. The problem is that they all seem to merge while they're doing that. Right now, every enemy is in the "enemy" type and they all have a pivot at their feet that controls placement/gravity. I can't figure a way to get each enemy to calculate the distance between each other and stop to allow movement and not have them all jumble into one. Any ideas? Thanks


WolRon(Posted 2006) [#2]
Wouldn't an easy solution be to just set up Collisions between the goblins? That way, even though they try to reach the same point, they can only ever get as close as touching each other.


Shifty Geezer(Posted 2006) [#3]
I'd guess start at goblin number one of move him. Then for the next goblin, compare his movement to 1's position and offset. Goblin 3 needs to be checked with 1 and 2, and 4 checked with 1,2,3 etc. Or do like Blitz3Ds sphere collision demo and assign each a sphere collision type and deal with it just like that demo!


octothorpe(Posted 2006) [#4]
A simple solution might involve checking the distance between each enemy and generating a force to push them apart if they get too close. There may be cases where this strategy will fail, but if you tweak it enough it might be useful.

Here's some awful code I hacked up in the middle of the night to show you the general idea:

Quite a lot of optimization could be done. For one thing, there's no real need to take square roots. Also, there's no need to calculate the distance from B to A if you've already done A to B.


Tyler(Posted 2006) [#5]
Thanks for the responses! I've tried the regular collisions method and it does very strange things to my engine. Especially spherical collisions. Sometimes the goblins end up sliding below each other or rest on top of one another when they spawn. I also have to consider that their gravity is dependent on collisions from their feet pivot to the level's ground (which seems to be overridden when they're also checked for collisions between one another, hince the golbin-jinga effect) My first thought to counter all the collision oddities was to just check distance ... then I got stumped trying to figure how to go down each enemy type, check it's model and each other enemy's model, when enemy\model 's X, Y, Z could be confused amongst a nested for each loop.

Anyhow, thanks for the distance checking code! I'll play around with it when I get home.