Right, my main character has a spawnpoint which is a child of him, that spawnpoint creates a sphere consisting of a box collider. Now the problem I’m having is that when I shoot that sphere, it doesn’t collide with the enemy. Each enemy has 2 lives (set in the inspector). This is my script.
// variable to store the enemy ragdoll
public var ragdoll:GameObject;
public var enemyLives:int = 0;
function onCollisionEnter (enemyhit:Collision)
{
print("Testing collision");
if (enemyhit.name == "Enemy") {
GetComponent(enemyShot).enemyLives--;
if (enemyLives <= 0)
Instantiate(ragdoll, transform.position, transform.rotation);
animation.CrossFade("die");
Destroy(this.gameObject);
}
}
Each of the enemy consist of a Character Controller. I’ve put RigidBody, box colliders etc on every single one of them + the child, the sphere still doesn’t collide. Did the same for the sphere, nothing is colliding. If anyone can help on this, it’d be greatly appreciated.
OK here is my setups, I made a simplified version, I have a sphere which act as your bullet, it has rigidbody, sphere collider (no IsTrigger) and just a movement script. Then i have another sphere that acts as your enemy with CC, rigidbody (IsKinematic) and a sphere collider (no IsTrigger).
It has only this script:
var lives = 5;
function OnCollisionEnter(other:Collision){
if(other.gameObject.tag =="Sphere")
Debug.Log("Collision");
lives-=1;}
And it works. I have not altered any other members of it all, just add components and that is it. MAybe you could add a collider to your enemy. As you rigidbody is set to IsKinematic, it won’t interfere as IsKinematic disables the collider.
// variable to store the enemy ragdoll
public var ragdoll:GameObject;
public var enemyLives:int = 0;
function onCollisionEnter (enemyhit:Collider)
{
print("Testing collision");
if (enemyhit.CompareTag("Enemy") {
GetComponent(enemyShot).enemyLives--;
if (enemyLives <= 0)
Instantiate(ragdoll, transform.position, transform.rotation);
animation.CrossFade("die");
Destroy(this.gameObject);
}
}
ok what you did wrong was try to find its name. Make a tag. then assign it. and its not :collision its :collider. did you get any output after you changed it to mine?