# Unity Ai Tutorial

**URL:** https://discussions.unity.com/t/unity-ai-tutorial/28596
**Category:** Questions & Answers
**Created:** [September 17, 2011, 9:26pm UTC](https://discussions.unity.com/t/unity-ai-tutorial/28596 "2011-09-17T21:26:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [September 17, 2011, 9:26pm UTC](https://discussions.unity.com/t/unity-ai-tutorial/28596/1 "2011-09-17T21:26:46Z")

</div>

Does anyone know of a good tutorial that could show me how to make a health bar, make an enemy which could cause damage until the player dies and then have a re spawn button?

---

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [September 18, 2011, 1:48pm UTC](https://discussions.unity.com/t/unity-ai-tutorial/28596/2 "2011-09-18T13:48:00Z")

</div>

here is a tutorial but it is very long.

> **[BurgzergArcade.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=burgzergarcade.com)**
>
> Friendly and helpful customer support that goes above and beyond. We help you get the perfect domain name.

---

<div class="post-metadata">

### Author: ![MrLolEthan](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@MrLolEthan](https://discussions.unity.com/u/MrLolEthan)
#### Post date: [October 12, 2012, 5:00pm UTC](https://discussions.unity.com/t/unity-ai-tutorial/28596/3 "2012-10-12T17:00:01Z")

</div>

For the AI to make something follow you, you want to use something like this script I wrote:

```
function Update() {
	    enemy.transform.LookAt(target);
		enemy.transform.position = Vector3.Lerp(
		enemy.position, target.position,
		Time.deltaTime * moveSpeed);
}

```

Then you want to use the variables:

```
var target : Transform;
var enemy : Transform;
var moveSpeed : float = 5.0;

```

You can select the items as the target and the enemy (which chances are is the gameobject the script is attached to) in the unity Inspector view under the script options. The complete script should look something like this:

```
var target : Transform;
var enemy : Transform;
var moveSpeed : float = 5.0;

function Update() {
	    enemy.transform.LookAt(target);
		enemy.transform.position = Vector3.Lerp(
		enemy.position, target.position,
		Time.deltaTime * moveSpeed);
}

```

PS: If you don’t understand what i’m talking about you should start with something easier.

Also learn about Vector3s and Vector3.Lerp. You can read up about Vector3’s [HERE](http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Vector3.html) and Vector3.Lerp [HERE](http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html).
