- Home /
Question by
goosoodude · Feb 21, 2012 at 02:43 PM ·
fpsaiprojectile
Projectile not inflicting damage on AI
Hello. I have a projectile, but it is not casing damage. I tried using this line of code:
if(Physics.Rocket(Rocket, hit)){ // if something hit, send the message hit.collider.SendMessageUpwards("ApplyDamage", 800, SendMessageOptions.DontRequireReceiver);
and it would return Compiler errors. I don't know what to do. Also, my projectile script is below.
// The reference to the explosion prefab
var explosion : GameObject;
var timeOut = 3.0;
// Kill the rocket after a while automatically
function Start () {
Invoke("Kill", timeOut);
}
function OnCollisionEnter (collision : Collision) {
// Instantiate explosion at the impact point and rotate the explosion
// so that the y-axis faces along the surface normal
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation(Vector3.forward, contact.normal);
Instantiate (explosion, contact.point, rotation);
transform.Translate(Vector3.up * Time.deltaTime);
// And kill our selves
Kill ();
}
function Kill () {
// Stop emitting particles in any children
var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
if (emitter)
emitter.emit = false;
// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
transform.DetachChildren();
// Destroy the projectile
Destroy(gameObject);
}
Comment
Answer by Berenger · Feb 21, 2012 at 10:10 PM
What is that function Physics.Rocket ?
That might be your problem then ^^
I think you want to use either Physics.OverlapSphere (it returns an array with every collider in the sphere you give in argument) Or Physics.Raycast (Cast a ray in a direction and tells if it collided with something, and give you infos if it did).