Anyway, i've got the code which moves then forward smoothly, but i'm having a bit of trouble getting them to turn smoothly, more precisely when to stop turning them.
I'm using a time based method, so each time through the game loop it checks if any agents are currently wishing to turn, and then turns them a certain amount based on the elapsed time if they do need turning.
Here's my code which checks whether they've reached their desired direction (if they have then they'll stop wanting to turn):
(apologies for it being java, should be simple enough to understand tho!)
Code: Select all
private boolean notAtDestinationDirection() {
if (destinationDirection.getZ() == -1 && turningRight && forward.getZ() > -1)
return true;
else
if (destinationDirection.getZ() == -1 && !turningRight && forward.getZ() < -1)
return true;
else
if (destinationDirection.getX() == 1 && turningRight && forward.getX() < 1)
return true;
else
if (destinationDirection.getX() == 1 && !turningRight && forward.getX() > 1)
return true;
else
if (destinationDirection.getZ() == 1 && turningRight && forward.getZ() < 1)
return true;
else
if (destinationDirection.getZ() == 1 && !turningRight && forward.getZ() > 1)
return true;
else
if (destinationDirection.getX() == -1 && turningRight && forward.getX() < -1)
return true;
else
if (destinationDirection.getX() == -1 && !turningRight && forward.getX() > -1)
return true;
else
return false;
}
So there's something wrong with my code above i guess, as it's not stopping at the right point, so if anyone else has any experience with this (there should be lots of people!) then maybe you can see what's wrong or suggest a better method, just say if you need anymore code or explanation!
