Ahoy Unityers!
I’m having an extremely annoying problem w/ projectiles and ClosestPointsOnBound.
I’m trying to detonate a missile and find the closest point to the detonation on a nearby object. My code is as follows:
if (hit.rigidbody) {
var closestPoint = hit.collider.ClosestPointOnBounds(transform.position);
direction = closestPoint - transform.position;
print(hit.name + " " + transform.position + " " + closestPoint + " " + direction.normalized);
print(transform.position.x + " " + transform.position.y);
print(closestPoint.x + " " + closestPoint.y);
}
What I’m finding is that transform.position and closestPoint are IDENTICAL. However, the detonations are CLEARLY happening well above the object. Why!!?? :[.
Right now, i’m going to try to work around it, but ClosestPointOnBounds seems REALLY useful and I’d really like to know how to use it properly.
Thanks!
-Sean