Open drewmalin opened 12 years ago
The first direction I would head with dynamic collision detection would be to maintain a map of uncrossable lines, but I've read nothing about pathfinding so that may be super inefficient or something.
The nice thing about the current method of movement is that if a unit is walking along a path that will pass through an unfinished building foundation, the unit will swerve out of the way if the building is finished before it passes. I undoubtedly don't know enough about pathfinding, but I just wonder about the efficiency of recalculating the path several times for a unit before it reaches its destination.
That said, I see pathfinding as a necessity and assume its fairly constant recalculation won't actually be a huge issue.
What if we represented the map as an array of bits (or booleans)? Say our visual map is 10 by 10, so we maintain an array of equal dimensions. If we need more detail than that, we can increase it so that each visual tile actually represents 4 or 16 values in the pathfinding map, or we can decrease it such that each entry in the pathfinding map corresponds to 4 or more visual map tiles. From there: is a point on the map collidable? 1, else, 0.
Maybe certain types of rivers (depth) and folliage, certain terrain types, and static objects (trees) would modify the collision map.
We also need a check on the difference in height of two points.
if ((currentPosition.y - nextPosition.y) < MAX_HEIGHT) {
//discard this step as part of the shortest path
}
Regarding recalc of paths, it seems reasonable to store a currentPath and test its validity at time intervals instead of constant recalc. Recalc only if currentPath no longer valid.
I agree. Every frame would be overkill, though we want to do it often enough to avoid the corner case of creating objects in the path of a moving unit.
Maybe we could force a recalc only when a new object is placed on the map -- only when the player selects a location for building, and then again only if buildings or objects are destroyed.
I still want to revisit the idea of regrowing organic static entities...
Currently the pieces are in place to allow individual units to construct buildings, but they need to be tied together such that the unit itself can carry out the entire process--from gathering the necessary resources to modifying the foundation terrain to placing the building model.
Some thoughts on this: