This site requires JavaScript, please enable it in your browser!
Greenfoot back
Back to discussions
jokhooo
jokhooo wrote ...

2017/11/12

how make enemy get position of player

jokhooo jokhooo

2017/11/12

#
I will make a game platform, how to make opponents can detect the position of player who approached him (opponent) i use the following method for player
      public int getnilaiX() {
        return getX();
    }
    
    public int getnilaiY() {
        return getY();
    }
and, this method for enemy
    public void cekPlayer()
    {
        int x = ((player) getWorld().getObjects(player.class).get(0)).getnilaiX();
        int y = ((player) getWorld().getObjects(player.class).get(0)).getnilaiY();
        
        if (y <getY()+2 && y > getY()-2 && jumping == false)
       {
           jump();
       }
    }
    
But, the enemy cant get nearest position of player for illustration like this Thankyouu
danpost danpost

2017/11/12

#
See here.
You need to login to post a reply.