The question is answered, right answer was accepted
why won't my collision script work?
I'm trying to make it so that the AI jet from the Standard Assets package will crash & burn in the event of a collision with other jets or terrain. I'm working from the Scripting API; https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
For testing purposes, I attached my script to a cube, gave it a rigid body component with "Is Kinematic" un-ticked, and positioned a 2nd cube (also w/ non-kinematic rigid body) above, so that it falls onto the first... but my collision event does not get triggered.
My script is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Vehicles.Aeroplane;
public class JetCollision : MonoBehaviour {
public AeroplaneController Jet;
public int Jethealth = 5;
public GameObject KillPointExplosion;
public GameObject JetSoundToStop;
void OnCollisionEnter(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
if (collision.relativeVelocity.magnitude > 2)
Jethealth = 0;
}
void Update(){
if (Jethealth == 0) {
KillPointExplosion.SetActive (true);
JetSoundToStop.SetActive (false);
Jet.Immobilize ();
}
}
}
The OnCollisionEnter bit is taken nearly verbatim from the example code given in the API - I just changed "audio.Play();" to "Jethealth = 0;"
I'd love to know what I'm doing wrong, if anyone can see what the problem is.
Thanks, and cheers!