Hello,
i try do code a method which spawns a bullet at the position of the player and then move to the nerest Object of a given class.
It works if there is one Object of the Enemy1.class on the World, but if there is a second and im nearer it it, the bullet still moves to the other Object.
Thanks in advance
Sven
if(Greenfoot.isKeyDown("1") && !cd1){
if(!getObjectsInRange(350, Enemy1.class).isEmpty()){
Actor target= (Enemy1) getObjectsInRange(350, Enemy1.class).get(0);
Actor bullet = new Bullet();
((Main)getWorld()).addObject(bullet, getX(), getY());
bullet.turnTowards(target.getX(), target.getY());
bullet.setImage("frost.png");
cd1counter = 80;
cd1=true;
}
}
