[SOLVED] Fear effect should make enemy flee not working

Hello, when this.state=fear the enemy should flee, but the newEnemyPos changes and i can’t find why https://playcanvas.com/editor/code/674858?tabs=30277750,37466378 i’m looking into this for 2 days with no results. Can you see where i am at fault? Thanks.

var playerPos=this.Player.getPosition();

This gets a reference to the position vector which changes.

In this case you would want to copy or clone the vector when you assign the value to newEnemyPosition so that it isn’t affected by the Player moving.

this.newEnemyPos = playerPos.clone();

See if that helps

Now the code works…almost…when the enemy flee the animation stop…

Found the problem, thanks

1 Like