Something like this.player = this.app.root.findByName('Player');
in the initialize function of the script.
Then you can use this.player.getPosition()
to get a random destination around the player.
Something like this.player = this.app.root.findByName('Player');
in the initialize function of the script.
Then you can use this.player.getPosition()
to get a random destination around the player.
I’m not sure its working… I set patrol range to 1 to test and he does not follow me
The destination is a point in the scene the enemy tries to rotate to when it’s not avoiding obstacles. If there are no obstacles, you will see the enemy easily can reach this point. If the scene is full of obstacles (like your scene) it’s unlikely the enemy will reach this destination. This is because the enemy is just busy avoiding obstacles and can’t realy rotate in the direction of the destination.
Do you have any suggestions on how I can achieve my goal?
The patrol state is not meant to follow the player. If you want the enemy is following the player, your player entity need a Target
tag. That’s currently not the case.
I want it so the enemy is always searching by the player
Why you think it isn’t? I mean what do you expect? The enemy can’t follow the player if it can’t see the player as it is a ‘realistic’ AI.
Yeah, I just don’t want the enemy searching on the other side of the map sometimes, I have no idea what I should do…
Again, it’s the limitation of not having pathfinding. The enemy can move around but doesn’t realy know where to go. To be honest, I’m already surprised the AI works that well in a scene full of obstacles and a lot of different rooms.
The only solution I can think of is to have more enemies. I mean, why you have a huge scene with a lot of rooms and only one enemy? I think if this was real life the enemy also would lost the player?
For a map like mine, what sensor length should I use?
Probably something like 0.8
. (If the sensors are longer the AI has less free space to move around).
How do I add the chase timer attribute back? I want my chases to last longer
There is a timer in the chase state, so you can make the timer slower to have a longer chase time.
// currently
this.enemyTimer += this.enemyMoveSpeed * dt;
// slower
this.enemyTimer += this.enemyMoveSpeed * dt / 1.5;
Version 1.4 is released!
In this release move speed and rotate speed are separated to give the user more freedom in customization. The enemy stop distance is no longer hard coded, as it cause a conflict with a small attack distance for melee weapons. (Make sure the stop distance is always smaller than the attack distance, otherwise the enemy is not be able to attack). Also some attributes are renamed to make more clear what they are for.