x


FPS Tutorial AI robot (AI) Not loosing health.

I made sure that the character controller was formed around his body. I am using the official Unity FPS tutorial Script (CharacterDamage) and it has not been modified. Yes I have unity pro trial.But when i had it in normal it still wouldn't work. The script:

var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;

function ApplyDamage (damage : float) {
    // We already have less than 0 hitpoints, maybe we got killed already?
    if (hitPoints <= 0.0)
       return;

    hitPoints -= damage;
    if (hitPoints <= 0.0)
    {
       Detonate();
    }
}

function Detonate () {
    // Destroy ourselves
    Destroy(gameObject);

    // Play a dying audio clip
    if (dieSound)
       AudioSource.PlayClipAtPoint(dieSound, transform.position);

    // Replace ourselves with the dead body
    if (deadReplacement) {
       var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);

       // Copy position & rotation from the old hierarchy into the dead replacement
       CopyTransformsRecurse(transform, dead);
    }
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
    dst.position = src.position;
    dst.rotation = src.rotation;

    for (var child : Transform in dst) {
       // Match the transform with the same name
       var curSrc = src.Find(child.name);
       if (curSrc)
         CopyTransformsRecurse(curSrc, child);
    }
}
more ▼

asked Sep 23 '11 at 04:31 PM

goosoodude gravatar image

goosoodude
21 12 22 22

Seriously. Can i have some help

Sep 23 '11 at 05:44 PM goosoodude

Hello? I've been waiting over three hours to have an answer. Sorry for my impatience

Sep 23 '11 at 08:06 PM goosoodude

Doode, it takes longer than 10 minutes to find this script, and I stopped looking after 10 minutes. Maybe you should just post the code here so people can see (& analyze) it without having to download it and then search for which file you mean.

Sep 23 '11 at 08:09 PM RoughDesign

Also, it can take even days for a question to be answered. Demanding someone to answer like you do would require to pay that person. The people here do it for free, so your "Hello?" seems quite impolite.

Sep 23 '11 at 08:16 PM RoughDesign

Sorry the 101010 button is not working. And i didn't mean it in that way. It was like you walk up to a person and you say hello.

Sep 23 '11 at 08:21 PM goosoodude
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Left click:

function Update()
{
    if (Input.GetKeyDown(KeyCode.Mouse0))
    {
       ApplyDamage(50.0f);
    }
}
more ▼

answered Sep 23 '11 at 11:53 PM

J3 Gaming gravatar image

J3 Gaming
244 17 21 24

In order to find out your exact problem, we would need to see the weapon script.

This script will be attached to the gun and it calls ApplyDamage (or at least it should for this to work)

Sep 23 '11 at 11:55 PM J3 Gaming

That worked!!! Thank you very much!!!!

Sep 24 '11 at 01:22 AM goosoodude

Also thumbs it up too, it helps with points here

Sep 26 '11 at 08:54 PM J3 Gaming

I'm not allowed. I just don't have permission

Sep 26 '11 at 09:14 PM goosoodude
(comments are locked)
10|3000 characters needed characters left

Everything seems right with the function ApplyDamage...
Insert

function Update () {
if (Input.GetKeyDown ("space")) ApplyDamage(30.0);
}

before it and then test the function, the robot will receive damage everytime you press space in the game.
If that works, your problem is that the function ApplyDamage is not called when the robot is hit.
Then the problem would be in the script of the bullet or weapon.

more ▼

answered Sep 23 '11 at 11:12 PM

RoughDesign gravatar image

RoughDesign
26 4 4 6

Wait, what if i want to use the left click?

Sep 23 '11 at 11:49 PM goosoodude

This is only to check out if this script is working as it should. Just like the answer from MightyGoob, it does ApplyDamage whenever you press the button (no matter where you aim).
In Explosions on page 11 of the tutorial you can see how an explosion calls ApplyDamage in the colliders it touches.

Sep 24 '11 at 08:58 AM RoughDesign

Oh and thanks for your help too!

Sep 24 '11 at 01:55 PM goosoodude
(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:

x5059
x1171
x956
x248

asked: Sep 23 '11 at 04:31 PM

Seen: 1036 times

Last Updated: Sep 26 '11 at 09:14 PM