x


coliders are not working

hey, so i`m making a game and the bullets that hit the player are damadging him but the ones that hit the ennemy are not, the player is a capsule all made in Unity but the gun, the turret was fully made in cheeta 3D so I added a box colider to it and tried just adding coliders in the prefab options annyway I cant find a reason for this to hapen other than a bug. so here are the codes I used.

// under update in the shooting code
if(Input.GetButtonDown("Fire1")&& fire)
    {
        if (auto){}

        else
        {
        clone = Instantiate(projectile, transform.position, transform.rotation);
        clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
       AudioSource.PlayClipAtPoint(sound, transform.position, 1);
       bulletAmount -= 1;
        }
    }   


// under the health script and update
var dead = false;
var health = 100;
var damage = 10;
var player = true;
var ennemy = false;
var PlayerHealthDisplay: GUIText;

function DisplayAmount () {
    PlayerHealthDisplay.text = "" + health;
}

function Start () {

}



function OnControllerColliderHit(hit : ControllerColliderHit) 
{    

    if (hit.gameObject.tag == "fallout")
    {
       dead = true;
    }

    if (hit.gameObject.tag == "bullet")
    {
     if (player)
     {
     health -= damage;
     }
     if (ennemy)
     {
     health  -= damage;
     }
    }

    if (health < 1)
    {
    dead = true;
    }

}

function Update()
{
       if (dead && player)
       {
           Debug.Log("Died, Respawning!");
           health = 100;
           transform.position = Vector3(-9,2,-48);
           dead = false;
       }
       if (dead && ennemy)
       {
            Destroy(gameObject);
       }

}

// and under the bullet code
var lifeTime = 100;


function Awake()
{
    Destroy (gameObject, lifeTime*Time.deltaTime);
}
function OnCollisionEnter(collision : Collision)
{
    Destroy (gameObject,0.1);
}

sorry for the ton of code and thank you all

more ▼

asked Jun 05 '12 at 12:19 AM

thenachotech1113 gravatar image

thenachotech1113
131 2 11 21

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html According to the document, one collider must have rigidbody attached to it. You should try attaching to bullet or something.. i guess..

Jun 05 '12 at 01:32 AM PforPepsi

Also, CharacterControllerHit only activates when you use Move function attached. I'm not sure because when i tried, it didn't work at all.. Just in case, here is the reference http://unity3d.com/support/documentation/ScriptReference/CharacterController.OnControllerColliderHit.html

Jun 05 '12 at 01:35 AM PforPepsi
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Hey, try to add Rigidbodys with collisiondetection to your enemys this should work :).

more ▼

answered Jun 05 '12 at 09:31 PM

Driseus gravatar image

Driseus
35 1

ok great thank you

Jun 12 '12 at 12:09 AM thenachotech1113
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x651
x308
x280
x248
x5

asked: Jun 05 '12 at 12:19 AM

Seen: 352 times

Last Updated: Jun 12 '12 at 12:09 AM