I'm still working on my tower defense game at the minute, and I've hit another brick wall.
For testing I'd like to find a way of making the towers rotate around their origin on the Y axis to follow an enemy if it's within range of them.
So for example if an enemy is walking down the path towards them I'd like them to rotate slowly to ensure that they're always facing in the right direction.
if(e.getWorldPos().getX() < (-t.getPosition().getX()) + t.getRadius() && e.getWorldPos().getX() > (-t.getPosition().getX()) - t.getRadius())
{
double xRot = Math.sin(t.getPosition().getX() - e.getWorldPos().getX());
System.out.println(xRot);
t.setCurrentRot((float)xRot);
}
Obviously I'll do the same for the Y axis checking as well, but am I anywhere near the right track for this? I have no idea if Sin's the correct mathematical function to use here, sorry.
Any assistance will be helpful here.
BTW: e is the very first enemy in the wave and t is a tower.
Cheers,
Ollie.