Simple AI scripting. (move towards the player - C#)

I’m trying to find C# tutorials for basic AI without much luck. I basically need two very simple behaviours: one for an enemy that starts moving towards the player with the intention of crashing into him as soon as the player gets within a certain radius and he “notices” him.

The other is an enemy that does the same, but instead of crashing into the player it would stop a short distance away and shoot projectiles at the player and try to maintain that distance (so if the player moves towards the enemy, the enemy would back away).

I know I need to create special scripts to stick on the AI and place it on the update function: to see if the player is at a certain distance to the enemy or closer and then move towards the player. For the other player to shoot a projectile prefab towards the player every x seconds etc.

Are there any Unity/C# tutorials that touch that area?

you don’t mention how intellegent the player needs to be, for example are you going to have rooms/walls that they will have to negotiate? if not, you could use a basic Transform.Lookat(target as GameObject) and reduce the Vector3.distance between the 2 objects. if you really need a tutorial, please see this thread that I started over the weekend

http://forum.unity3d.com/threads/125790-tutorial-series?p=847255#post847255

Thanks! There are obstacles, but mostly rigid bodies I want the AI to push through.

1 Like