# A* Simple AI help !

 0 I am using A* in our RPG which is tile based. Players and enemies have two gameobjects with box colliders attached. One for the current and another I use to reserve the next tile while the controller moves the player or enemy from tile to tile. When not moving this 2nd collider is hidden.My A* implementation raycasts tile centre to tile centre at head height above the tile's floor and therefore sees these box colliders as impassible. Granted this does mean that the paths fail where two enemies walk in opposing directions but it is sufficient for m purposes and seems to scale well enough so far.You could of course, upon collision with these box colliders during pathing attempt to negotiate with the owning enemy and naturally there may actually be a path by the time the enemy gets there, but it's reasonable to just repath later, if potentially computationally more expensive.Hope that helps Ian H more ▼ answered Sep 21 '11 at 11:25 AM Bovine 1.6k ● 26 ● 30 ● 47 Obviously I'd you find your entities would collide moving from tile to tile, you can halt following the path and repath from there, presuming your blockage will go eventually.You might want to consider using behavior trees to make some of the decisions about where to path to and what waypoints to pick. Check out AngryAnt's free unity implementation at http://www.AngryAnt.com. And follow his links to read and watch videos about BTs on http://www.aigamedev.com Sep 21 '11 at 11:29 AM Bovine Generally tile-based path-finding is done entirely through your 2D array. Instead of using a collider to claim a "move to" space, mark it as used in the array. Instead of raycasting to check whether a path is open, use math to directly check the `used` variable of the squares you will move through. Sep 21 '11 at 01:05 PM Owen Reynolds @Owen Reynolds we did not use an array because our movement is tile based but our world is fully 3D so we would really need a 3D array. Players and Enemies can walk along each level but that level is not necessarily flat and indeed there could be levels above or below where the player/enemy currently stands that are largely freeform.You could however avoid the raycasting and tile reservation colliders if you used Owen's suggested approach for a tile based game. If however your world is 3D you could still consider my tile reservation approach, but consider that your are reserving a node.Efficient use of layers reduces the cost of raycasting and tile reservation. Sep 21 '11 at 08:38 PM Bovine It's worth noting that as @Owen Reynolds says, with a grid raycasting can be avoided. We are considering restructuring our level collision models so that we can precompute a grid for a given level. This is not trivially, but I think I have a way. For a tile based implementation, I can then precompute things like tile heights, whether a tile is open or closed, whether it is possible to pass from one tile to the next, all things I am currently computing on the fly. Naturally this also means that logic needs updating for when doors and barriers are opened/closed to make changes to the relevant map tile, or perhaps the edge. We'll then need a way for the player (or enemy) to pass from one grid to another without issue.So if I do all of the above, there's some work to do in the editor to create these maps and some work to do allowing player's and enemies to transition from map to map and we know longer need a 3D array, more we accept that players are bound to a tile and nothing can pass above or below them unless it does so within a separate map, which would only be an issue for flying creatures, so unlikely to be an issue at all in this first pass.This fairly considerable amount of setup means that path finding and movement will be more efficient and indeed, I wouldn't even need the player or enemies to move via a CharacterController.It looks like there may be a masterclass on collision avoidance (which was the original topic) on http://aigamedev.com but you'll need a premium account to view it. I would check but I have issue logging in sometimes...http://aigamedev.com/premium/event/session-collision-avoidance/ Sep 23 '11 at 08:43 AM Bovine add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: