- Home /
This post has been wikified, any user with enough reputation can edit it.
Enemy Collision Wont Work! PLEASE HELP
In my game im making it so that when the player touches something it will Trigger the enemyspawn. This part works perfectly. But I have a problem. When the spawn Instantiates the enemy, the enemy wont take damage from my attacks, they just "bounce" off him. The original enemy takes damage from my attacks but the Instantiated "Clones" do not. PLEASE HELP, my game is at a stand still til I figure this out.
var target : Transform; //the player
var speed : float = 5; // well...the speed
var controller:CharacterController;
var enemyLife : int = 100;
var Explosion : GameObject;
var Death : GameObject;
function Start()
{
controller = gameObject.GetComponent(CharacterController);
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update()
{
transform.LookAt(target); // the NPC looks at the player
// Here you access the Character Controller component and move your NPC with SimpleMove() giving the speed and the direction(forward).
//As the NPC is looking at you, forward is in your direction.
controller.SimpleMove(speed*transform.forward); // Moves forward
if (enemyLife <= 0) //Death
{
Destroy(gameObject);
var instance8 = Instantiate(Death,transform.position,transform.rotation); //Explodes
Debug.Log("Enemy was killed");
}
}
function OnCollisionStay (other : Collision)
{
if(other.gameObject.name == "FireBall(Clone)")
{
enemyLife -=20;
Destroy(other.gameObject);
var instance = Instantiate(Explosion,transform.position,transform.rotation);
Debug.Log("Enemy was hit");
}
else if(other.gameObject.name == "PhotonBall(Clone)")
{
enemyLife -= 24;
Destroy(other.gameObject);
var instance2 = Instantiate(Explosion,transform.position,transform.rotation);
}
else if(other.gameObject.name =="Shock(Clone)")
{
enemyLife -= 23;
Destroy(other.gameObject);
var instance3 = Instantiate(Explosion,transform.position,transform.rotation);
}
else if(other.gameObject.name == "FrostBall(Clone)")
{
enemyLife -= 25;
Destroy(other.gameObject);
var instance4 = Instantiate(Explosion,transform.position,transform.rotation);
}
else if(other.gameObject.name == "AquaBall(Clone)")
{
enemyLife -= 34;
Destroy(other.gameObject);
var instance5 = Instantiate(Explosion,transform.position,transform.rotation);
}
else if(other.gameObject.name == "PlasmaBall(Clone)")
{
enemyLife -= 35;
Destroy(other.gameObject);
var instance6 = Instantiate(Explosion,transform.position,transform.rotation);
}
else if(other.gameObject.name == "SpitFire(Clone)")
{
enemyLife -= 16;
Destroy(other.gameObject);
var instance7 = Instantiate(Explosion,transform.position,transform.rotation);
}
}
Comment
Set to is$$anonymous$$inematic, which ignore physics. Then use OnTriggerEnter()
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Enemy deals damage to player on contact 2 Answers
Collision vs Trigger [Solved] 5 Answers
Fist Punch Collision 0 Answers
Damage on collision with player.. 1 Answer