- Home /
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);
}
}
Hello? I've been waiting over three hours to have an answer. Sorry for my impatience
Doode, it takes longer than 10 $$anonymous$$utes to find this script, and I stopped looking after 10 $$anonymous$$utes. $$anonymous$$aybe 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.
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.
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.
Answer by J3-Gaming · Sep 23, 2011 at 11:53 PM
Left click:
function Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
ApplyDamage(50.0f);
}
}
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)
Answer by RoughDesign · Sep 23, 2011 at 11:12 PM
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.
This is only to check out if this script is working as it should. Just like the answer from $$anonymous$$ightyGoob, 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.
Your answer
Follow this Question
Related Questions
Ai that applies damage when in range? 1 Answer
Bootcamp damage 0 Answers
Deal damage on collision 2 Answers
zombie ai script 1 Answer
fps tutorial problem 2 Answers