woensdag 10 november 2010

The path has been found, let's move forward!

We've improved the pathfinding in the time management game. The system was working very good already but had some drawbacks when moving the actual character model along it's path. It just followed the tiles one by one until it reached it's target. Moving the character model from tile to tile results in this kind of movement:




















As you can see, the movement of the character model is very mechanical like. A human would never walk like this in an open aera. But rather move in a straight line. We also want this more logical movement in the time management game.




















I read several articles on how to find shortcuts in these kind of paths. I was looking for a simple solution which was easy to add to the current pathfinding/movement system we have. For now we use this;

When the path is found, the system is going to cast a ray from the tile the character model stands on towards the last tile node in it's path. Two things can happen obviously. If the ray doesn't hit anything it means that the character model can directly move towards the last tile in the path, ignoring the other path nodes. If the ray does hit something the ray is being cast again towards not the last node, but the node before it. If it doesn't hit, character can move directly to that node. If it does hit it needs to cast a ray again. It seems to work pretty good, The character models now move in a more human like type of motion.

Doing it this way has some drawbacks. First, it isn't the fastest way. Casting a ray is not cheap. We also need a seperate mesh to define the 'walls' to ensure that the ray will hit a wall. In the time management game this is all fine. The environment is static and isn't that big.













-- Joep

Geen opmerkingen:

Een reactie posten