How to perform one pass collision detection on many objects?

I am implementing A* algorithm with obstacles tagged as Obstacle. I have a Board class that holds a grid of Nodes - discretized Plane ‘tiles’ with its coordinates.

I need create a map of walkable/unwalkable Nodes with collsion detection. What I came up with is :

Create a temporary GameObject with BoxCollider and keep translating it from one Node in the Board to another and check everytime if it collides with anything with Obstacle tag.

Now how can I do it if I do not have a single OnCollisionEnter() (or other function for collisions) but I have :

  • a plane with pathfinding script attached
  • many Obstacles
  • temporary BoxCollider which I do not know where to create (in which script)

How should I do this ? Where to perform this collision checking ? I think I can create a flag that would indicate whether the walkable/unwalkable map needs ‘rebuilding’.

You can use raycasting for what you want to achieve and it should give you better results. If you have the list of Nodes on your pathfinding script. All you have to do is use Physics.Raycast from one node to another and check if it hits an obstacle.

Ok so the way I have completed this is to iterate over each Node in Board and SphereCast it from above e.g. node (0,0,0) from (0,100,0) (assuming Plane on which characters walk is horizontal).

This works perfectly :slight_smile: