Hey guys,
I trying to create some simple AI for my enemy class. I have an enemy moving 0 degrees initially, and I want to make him move smoothly to angle 270 (straight down in my coordinate system). How can this be done?
With my current code, he ends up “taking the long way around” so to speak but it works fine for transitioning from 180 to 270 (left to down). I’m looking for something that will transition smoothly no matter what the chosen direction is and preferably so he would take the shortest route to get there.
This seems like it should be simple, but it’s driving me nuts! I am posting my code below which doesn’t quite work. In the below example, the variable direction is fixed at 270.
public void doBehavior(GameObject g)
{
int currentDirection = g.getDirection();
// Smooth transition from current direction to new
if(currentDirection < direction)
{
g.setDirection(currentDirection + 1);
}
else if(currentDirection > direction)
{
g.setDirection(currentDirection - 1);
}
}