- Home /
Too subjective and argumentative
FPSTutorial: AI robot not taking any damage
Hi! This is a followup to the last question. I have used all of the official tutorial resources and PDF document. But, I just cant get the robot to take any damage! It will first run in place the other way from me, then when I shoot it, it doesn't die! I've tried to add a box collider and numerous things, but it just doesn't do a darn thing! Thank you! Oh yeah, here's my 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);
}
}
Everything should work properly right off the bat. Have you changed anything? Try re-downloading and opening the project.
so what i do is delete the first one? in the original script or the script in the other quesiton?
Answer by Kith · Jul 22, 2011 at 07:31 PM
if (hitPoints <= 0.0)
return;
This looks like it would be the problem. You're checking to see if(hitPoints
The first if avoids the enemy to die again; if hitPoints>0 it's alive and can be hit. After receiving the damage, the second if checks if this damage killed the enemy.
Answer by goosoodude · Jul 22, 2011 at 08:26 PM
so, i need help, can you please post the whole code the way it is supposed to be?!?!?!?!?!?
Please do not post comments or questions as answers. @$$anonymous$$ith has provided what looks like the correct solution; take a second to try to parse the meaning out of his string of words. If you can't figure it out, consider trying a more basic program$$anonymous$$g tutorial.
seriously, please! I just need the script. I am not a very good scripter!
...@$$anonymous$$ith has literally listed the answer; just eli$$anonymous$$ate that code. I understand you're not the greatest scripter but you've gotta think about these things if you want to improve. Otherwise you're going to be here for every problem you have.
I'm sorry to burst your bubble, but I know how to move, I know a lot of things about Unity3D. Oh yeah, that was not the answer! I deleted that part of the code and it said "All compiler errors have to be fixed to enter playmode!"
You're making it very difficult for us to help you. "All compiler errors have to be fixed to enter play mode". Yes, we know this. Can you tell us what your error is? Open up your console and see what it says. I'm sorry, but unless you're willing to pay me, I'm not going to write the script for you. If you're serious about learning how to program well, you're going to have to increase your problem-solving skills. I'll be happy to point you in the right direction, but this isn't a place for you to ask people to write your code for you.
So, what is the error? Because I assure you, the problem you were having before was due to that if statement you deleted.
Follow this Question
Related Questions
FPS Tutorial AI Damage not Working 1 Answer
on collision damage 1 Answer
Quick question about DamageReceiver script from FPS tutorial 1 Answer
FPSTutorial: AI robot not taking any damage! 2 Answers
AIs with guns and sentrys that fire 1 Answer