I have a missile with a capsule collider that impacts a space station with a box collider. They are both set to be triggers.
I want to orient the explosion to the normal of the collider on the space station that the missile impacted, at the point of impact. I thought I knew how to do that, but the orientation is not looking right.
The code below is the OnTriggerEnter function on the station being hit. It puts the explosion in the right place, but the orientation doesn’t look right. Sometimes I’ll be hitting the side of a box collider but the explosion is perpendicular to it. Is the collider normal being updated as it rotates with the object to which it is attached?
private void OnTriggerEnter(Collider other)
{
// normal getter is a ray. Back it out along the path of the missile
normal_getter.origin = other.transform.position - other.transform.forward * 10;
//point it in the direction of the missiles travel at the time of impact
normal_getter.direction = other.transform.forward;
//cast the ray to get the hitinfo. Hitinfo.normal *should* be the normal of the
// collider that is impacted
Physics.Raycast(normal_getter, out hitinfo);
//put the explosion on the point where impact was detected
explosions[hits].transform.position = other.transform.position;
//orient the explosion to the normal of the collider face
explosions[hits].transform.rotation = Quaternion.LookRotation(hitinfo.normal, Vector3.up);
explosions[hits].transform.parent = gameObject.transform;
hit_points[hits] = 1;
explosions[hits].SetActive(true);
hits += 1;
if (hits == 5) hits = 0;
}