- Home /
Question by
pokeyoshi3 · Aug 04, 2012 at 08:49 AM ·
fpsenemy aishooter
My Enemy AI doesn't work(FPS).
heres the AI:
var health = 100;
var shot : Transform;
var target : Transform;
var bullet : Transform;
var hurt = 20;
var damage = 20;
function Update () {
if(target == null){
target=transform;
}
var Player1 :Transform = gameObject.FindWithTag("Player").transform;
var bullet1 :Transform = gameObject.FindWithTag("Bullet").transform;
if(Vector3.Distance(transform.position,Player1.position)<30){
target=Player1;
}
if(Vector3.Distance(transform.position,bullet1.position)<1){
bullet = bullet1;
health-=damage;
}
transform.LookAt(target.position);
if(health == 0){
Destroy(gameObject);
}
}
My problem is, that the enemy takes no damage. and even with applydamage and sendmessage he takes no damage. and YES he has a rigidbody and a capsule collider.
sorry for my bad english.
Comment
Answer by fafase · Aug 04, 2012 at 08:52 AM
var health = 100;
var shot : Transform;
var target : Transform;
var bullet : Transform;
var hurt = 20;
var damage = 20;
function Update () {
if(target == null){
target=transform;
}
var Player1 :Transform = gameObject.FindWithTag("Player").transform;
var bullet1 :Transform = gameObject.FindWithTag("Bullet").transform;
if(Vector3.Distance(transform.position,Player1.position)<30){
target=Player1;
}
transform.LookAt(target.position);
if(health == 0){
Destroy(gameObject);
}
}
function OnCollisionEnter(other:Collision){
if(other.gameObject.tag=="Bullet"){
bullet = bullet1;
health-=damage;
}
}
I actually do not really get all processes you are trying...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Making a FPS, my gun floats sideways in front of me? 1 Answer
new to scripting need some fps controll help plz :) 2 Answers
Compiler error FPSplayer script 2 Answers