Hello,
http://imageshack.us/photo/my-images/849/problemd.png/
Heres the code that im using.
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);
if(sHH == 1 || mHH == 1){
warRpgScript.playerExp += warRpgScript.enemyExp;
mageRpgScript.playerExp += mageRpgScript.enemyExp;
}
// Play a dying audio clip
if (bodydieSound)
AudioSource.PlayClipAtPoint(bodydieSound, transform.position);
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);
}
}
function Detonate2(){ // Destroy ourselves Destroy(gameObject);
if(sHHH == 1 || mHHH == 1){
warRpgScript.playerExp += warRpgScript.enemyExp;
mageRpgScript.playerExp += mageRpgScript.enemyExp;
}
// Play a dying audio clip
if (headdieSound)
AudioSource.PlayClipAtPoint(headdieSound, transform.position);
// Replace ourselves with the dead body
if (deadReplacement2) {
var dead : Transform = Instantiate(deadReplacement2, 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);
}
}
function OnControllerColliderHit(hit : ControllerColliderHit){
if(hit.gameObject.tag == "sword"){
sHH = 1;
ApplyDamage(Random.Range(12,24));
bodyswordHHit = 1;
var tempbodyswordHit: Transform;
tempbodyswordHit = Instantiate(bodyswordHit, transform.position, transform.rotation);
var tempbodyswordHit2: Transform;
tempbodyswordHit2 = Instantiate(bodyswordHit2, transform.position, transform.rotation);
}
if(hit.gameObject.tag == "magic"){
mHH = 1;
ApplyDamage(Random.Range(2,10));
bodyswordHHit = 1;
var tempbodymageHit: Transform;
tempbodymageHit = Instantiate(bodymageHit, transform.position, transform.rotation);
}
}
function OnTriggerEnter( otherObject : SphereCollider){
if(otherObject.gameObject.tag == "sword"){
sHHH = 1;
ApplyDamageHead(Random.Range(34,48));
headswordHHit = 1;
var tempheadswordHit: Transform;
tempheadswordHit = Instantiate(headswordHit, transform.position, transform.rotation);
var tempheadswordHit2: Transform;
tempheadswordHit2 = Instantiate(headswordHit2, transform.position, transform.rotation);
}
if(otherObject.gameObject.tag == "magic"){
mHHH = 1;
ApplyDamageHead(Random.Range(2,10));
headswordHHit = 1;
var tempheadmageHit: Transform;
tempheadmageHit = Instantiate(headmageHit, transform.position, transform.rotation);
}
}
function OnCollisionExit(collisionInfo : Collision){
sHH = 0; mHH = 0; sHHH = 0; mHHH = 0;
}
Just to clear things the weapon im using has a capsule collider that has isTrigger checked and it has a kinematic rigid body also (not on the same object).
Even though i have two different functions for collisions im not getting any collisions at all. If i use function OnTriggerEnter( otherObject : SphereCollider) i get no collisions. If i replace that function with function OnTriggerEnter( otherObject : Collider) without the sphere, i get collision from every collision even from the sphere collider. I have been searching for an answer for hours.
If anyone can help much thanks!