anyone have any ideas on how to get collision working correctly?
var projectile : Rigidbody;
var speed = 60;
var Damage = 4;
var range = 1000;
private var hit : RaycastHit;
function Update ()
{
if( Input.GetButtonDown( "Fire1" ) )
{
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
Fire();
}
}
function Fire ()
{
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (audio)
{
audio.Play();
}
if (Physics.Raycast (transform.position, direction, hit, range))
{
hit.collider.SendMessageUpwards("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
this doesn’t seem to be transferring damage to the target… even though i have this on the targets:
function Detonate ()
{
Destroy(gameObject);
}
function ApplyDamage (damage : float)
{
if (totalhealth <= 0.0)
return;
totalhealth -= damage;
if(totalhealth<= 0.0)
{
Detonate();
}
}
Any ideas guys?