- Home /
using a Mesh Volume for AI
So in my game right now, im having boxes spawn dynamically to create routes an AI can travel in. Im trying to figure out a good way i could use these to create a pathfinding technique. please help.
Answer by whydoidoit · Feb 21, 2014 at 05:32 AM
So if I've got this right the boxes are the areas you can travel through?
If that's correct then each box is effectively a section of a nav mesh that can be traversed in any way right?
So presuming those things are true:
Join the boxes together using a data structure such that each box knows about its neighbours
Have the data structure hold the distance from the centroid of the box to the adjoining edge to give you an approximation of distance weight.
You could do this manually or automatically by writing an editor script to do the scanning.
Use an A* algorithm (mine's here: http://unitygems.com/astar-1-journeys-start-single-step/) to work out the shortest list of boxes to traverse to reach the destination, using the centroid to edge weighted value calculated above.
As your path follower enters each box do either:
a) Find the shortest distance from the current position to the adjoining edge of the next box
b) Find the shortest distance from the current position to the point on the adjoining edge of the next box which is itself the shortest distance to the exit from the next box to the subsequent one
b will look more natural.