Hello,
I have a small 3d space simulator on rails project (Unity 5.3) that I’m attempting to add enemy AI to. The player’s ship always moves forward on the Z axis. Enemies spawn from straight ahead or from the left or right sides of the screens. When the enemy ship gets within a specified proximity of the player’s ship, they change to an attack state. I’ve been using MoveTowards to bring the enemy ship to the proximity border. Once the ship reaches the border, I start having issues with the movement. I would like for the enemy ship to always stay out in front of the players ship (at least matched speed) and be able to move around on the X and Y axis so that it can attempt to avoid the player’s fire.
My question is, what is the best way to handle the movement when the enemy ship reaches the attack proximity area so that the ship always stays in front of the player and doesn’t fly away (or fall behind the ship)? Should I just have the enemy ship match the speed of the player’s ship and then use the negative value of the player’s ship speed (as the step in MoveTowards) to have the enemy ship move away from the player on the Z axis at the same rate that the player is moving?
Any thoughts/information is greatly appreciated!