- Home /
Question by
Le-Capitaine · Sep 10, 2014 at 03:19 PM ·
c#collisiontrigger
Getting a contact point between two triggers
I have this code for a Starfox-like shooter, controlled in a 2D plane advancing through a 3D rail:
void HazardCheck (Vector3 ray) {
RaycastHit hit;
if (Physics.Raycast (transform.position, ray, out hit, ray.magnitude)) {
if (hit.collider.tag == "Hazard" | hit.collider.tag == "AI") {
Vector3 returnPos = cam.rail.transform.InverseTransformDirection(Vector3.Reflect (ray, hit.normal));
returnPos.z = 0;
Damage ((int) (ray.magnitude * 10));
targetPos = returnPos;
Invul (1);
}
}
}
With obvious, straight-on collisions, it works like a charm, but no collision is registered with more delicate ones, like when there's too much of an angle between the ray and the normal. I've looked into SphereCast and CapsuleCast, but I need the hazards to be triggers and CheckSphere doesn't return a point.
In the meantime, I got a decent-esque hack going on using transform.forward, but what alternatives would there be?
Comment