Hi I am currently using the free version of A Star but have plans to buy the pro version soon. My question is, does it support any kind of sensing/ sensors or do we have to script them? If there are any scripts with sensors ready, or tips on how any of you guys using a star implemented AI sensing, please share them, thanks.
Im not sure what your trying to do here, but I will try and make some guesses~
If you are trying to have units avoid each other, Local avoidance is Built in to A* Pro and is easy (ish) to implement~ Just remember the move command does DeltaTime for you
If you are wanting Do Something when a enemy is in line of site OR you want to Do Something when within a distance from the enemy. The best thing to do is RayCast~
If you want to get line of site, RayCast at the enemy… if it hits something other then the enemy, your not in line of site.
Or if you are trying to get distance, Raycast at the enemy with everything else LayerMasked, and return the distance with RaycastHit.Distance~
If you don’t know much about Raycasting read This… and I can give you some sample scrips…
Thank you for your answer.
To be honest I currently have it setup in a way that I have a box collider trigger and when enemies enter this trigger they are added to a list of possible sensed enemies.
Then I use this list to check if the enemy can be seen, heard or smelled.
For seen, I use a ray cast and for the others I have other checks.
However in this way, I get low FPS when I have more than 10 enemies, I was wondering if there was a way that is already implemented in the a star solution that will be more optimized than my custom method or if there is a way to get better performance. Thanks in advance.
Hi
Sensors and such things are out of the scope of the A* Pathfinding Project. There are however ways to do it efficiently. Take a look at KD-Tree on wikipedia (more specifically KD-Tree for k-nearest-neighbour searches and/or range searches), or possibly quadtree if you have a limited map and enemies are uniformly distributed.
I am sure that if you search you can find some implementations of KD-Trees in C# which you can simply pass a list of your enemies positions and then query for all enemies within a distance.
Just wondering, do you have only one player, or more than one?
Also, how the hell can you get low fps when using only 10 enemies? Simply looping through all of them and checking their distances should take less than 0.1 ms (probably less than 0.01 ms).
Hey Aron, thanks for commenting,
I am getting good fps with about ~30 enemies now, the problem was that I had a grid which comes with a star free and I set at too big and it dropped the fps by alot. Part of the other problem was that each enemy had a list of his own and sensed other creatures around him every frame so if I had 10 enemies close to each other they all had a list of 9 elements which was looping and checking for sight, sound, smell every frame.
I made adjustments and found a balanced way. I will be checking the KD-Tree too, thanks for the suggestion.
You should try just using Raycasting, it might speed things up a lot~ Also remember that A* pathfinding is muti-threaded, try having it run on 2+ cores, It is an almost linear increase in performance for me!