Hey Community,
I have one Player, which I move with "w-a-s-d". This Player shoots on Zombies. These Zombies are automatically pointing to the player. Now i also need, that the Zombies automatically move to the Player till the Zombie reached the Player.
Does anyone have a snippet for me, how to move the Zombie to the Player? This is the actual source code:
Best Regards from Germany and have a nice Weekend!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Zombie here. * * @author (your name) * @version (a version number or a date) */ public class Zombie extends Actor { /** * Act - do whatever the Zombie wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void pointingTo(Actor o) { setRotation((int)(180*Math.atan2(o.getY()-getY(),o.getX()-getX())/Math.PI)); } public void act(){ Player p = (Player) getWorld().getObjects(Player.class).get(0); pointingTo(p); hingehen(); } }