- Home /
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
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..
Also, CharacterControllerHit only activates when you use $$anonymous$$ove 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
Answer by Driseus · Jun 05, 2012 at 09:31 PM
Hey, try to add Rigidbodys with collisiondetection to your enemys this should work :).