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

2017/10/21

[Help] Make Ai follow player movemen

jokhooo jokhooo

2017/10/21

#
I want to make AI that can follow the motion of the player. like if the player jumped he jumped too. is there anyone can help me? Thanks before :)
danpost danpost

2017/10/21

#
jokhooo wrote...
I want to make AI that can follow the motion of the player. like if the player jumped he jumped too.
The actor that follows the motion of the player will probably need not only a reference to that player, but also its last known location coordinates:
Actor player;
int playerX, playerY;
There are multiple ways to get the reference to assign to the Actor field (passing it in a parameter of the constructor or another method; or by getting it from a generated list of player objects in the world either in the act or addedToWorld method). Then, after comparing the current location with last known location, move AI actor and save new coordinates.
jokhooo jokhooo

2017/10/22

#
danpost wrote...
jokhooo wrote...
I want to make AI that can follow the motion of the player. like if the player jumped he jumped too.
The actor that follows the motion of the player will probably need not only a reference to that player, but also its last known location coordinates:
Actor player;
int playerX, playerY;
There are multiple ways to get the reference to assign to the Actor field (passing it in a parameter of the constructor or another method; or by getting it from a generated list of player objects in the world either in the act or addedToWorld method). Then, after comparing the current location with last known location, move AI actor and save new coordinates.
emm can you explain me an example of the method code used?
danpost danpost

2017/10/22

#
jokhooo wrote...
can you explain me an example of the method code used?
It can be done similarly to how 'theCounter' is done in the greenfoot tutorials on How to Access One Object From Another
You need to login to post a reply.