x


Unity Ai Tutorial

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?

more ▼

asked Sep 17, 2011 at 09:26 PM

Dreave gravatar image

Dreave
137 255 179 179

That is not AI. Is a HUD tutorial. The question is quite misleading. Could you change it pls?

Oct 30, 2012 at 04:16 PM Karsnen_2
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
more ▼

answered Sep 18, 2011 at 01:48 PM

kabel gravatar image

kabel
66 3 3 3

(comments are locked)
10|3000 characters needed characters left

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 and Vector3.Lerp HERE.

more ▼

answered Oct 12, 2012 at 05:00 PM

MrLolEthan gravatar image

MrLolEthan
56 15 12 14

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6114
x1336
x490

asked: Sep 17, 2011 at 09:26 PM

Seen: 7460 times

Last Updated: Oct 30, 2012 at 04:16 PM