Enemy reaction to Player

Hi everyone,



my game is getting greater each day :wink: Thanks for all those great answers to my previous posts!!!



But still I got some question: So let’s get started  :evil:



I have a player with a surfboard model, which I can move over the river! Now I created en enemy class (crocodiles) and put an enemy on the river! Now I want this enemy to react to the player movement. If the player gets into an defined radius around the enemy, the enemy should turn around and move towards the player. If a collision is detected (player and enemy, not radius of enemy) the game is over. If the player is out of the radius again, the enemy will stay still!

I made a little picture so you can understand what I mean:







Are there any test examples where something like this is done that I can take a look at? Thanks :wink:




I dont think there are any test examples for something like this, I dont understand why you eaven need them, it's  easy to figure it out.



Just make a vector from enemy to you player and its length will be the distance from enemy to player and if it get small enough then let the enemy engage (make enemy move along the vector that leads to player) and then if(enemy.intersects(player) game over.

Maybe you can use some code from here: http://code.google.com/p/jme-demos/source/browse/trunk/stardust/src/com/jmedemos/stardust/ai/FireController.java



The controllers isVisible() Method checks if the target is in range and if its in its field of view.

Then it fires a Ray towards the target and checks if there are any obstacles between the target and itself.




Thanks… got it working now :wink:

Hi,



I'm trying to play with something in this style, have some time, I put more reality in this type reaction to this would create agents using the BDI model, so that they learn to behave in accordance with the player and react as real as possible.