How can I create an enemy which follows and shoots the player. The enemy must be in the z-axis in a 3D-environment.
I know this isn’t exactly what you’re looking for but this should be fairly easy to adapt to 3D co-ordinates.
Use Unity’s navigation editor window to create a navigation map.
The navigation map helps any gameobject using Unity’s built in nav agent script to react to a target transform, or layermask if you want to target a group.
When the nav agent gets to a set distance from the target, or reaches the nav agents stopping distance (that’s set in the inspector) you can trigger his aiming/firing animations/ ray casting and do any damage health calculations.
You can also use the code LookAt for turning the player towards another object, a bit of IK could help you turn just the head or aim the gun.
Just remember you can pull this off in many ways, you can even do it withouth a nav map if you make your own script that constantly checks distance and then fires an attack event. Vector3.distance(npc.transform.position, player.transform.position) <= stopping distance
Hope this helps!
thank you