I have an enemy class that aims at my tank and shoots at it on increments but if i drive past them they turn alot faster than at a distance how can I make them turn at a steady speed??
Enemy code
I know that the problem is in the turn towards in the aim method but i don't know how to slow it down.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Animal
{
int fire = 250;
public Enemy()
{
setImage("enemy.png");
}
/**
* Act - do whatever the Enemy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(!getWorld().getObjects(Tank.class).isEmpty())
{
aim();
shoot();
}
}
public void shoot()
{
if (fire == 0)
{
getWorld().addObject(new EnemyBullet(getRotation()), getX(), getY());
Greenfoot.playSound("GunShot.mp3");
fire = 300;
}
if (fire > 0)
{
fire --;
}
}
public void aim()
{
Tank tank = (Tank)getWorld().getObjects(Tank.class).get(0);
turnTowards(tank.getX(), tank.getY());
}
