Hello! I’m having some issues with basic collider functions being used in (I think) a very basic way. I’ve got two objects:
-
A rocket, with a simple box collider covering its bounds. It also has a Kinematic rigidbody, and IsTrigger is checked. It is tall and narrow.
-
A small planet, that is one mesh, with a mesh collider. No rigidbody, not marked Trigger (but it still trips the OnTriggerEnter function just fine)
OnTriggerEnter is working perfectly! No matter how intricate my planet mesh, the function is called on the Rocket’s script only & exactly when the two colliders start to intersect.
Now I’d like to detect, roughy, where this collision happens. So I’m using this code, which seems pretty simple and straightforward:
class Rocket
{
void OnTriggerEnter(Collider planetCollider)
{
Vector3 rocketCenter = this.transform.position; //Center of the rocket
Vector3 closest = planetCollider.ClosestPoint(rocketCenter);
Vector3 closestBounds = planetCollider.ClosestPointOnBounds(rocketCenter);
}
}
But both closest and closestBounds are just giving me rocketCenter! Even when the rocketCenter is clearly NOT near the planet. Even if I make the rocket extra tall, so that the center is even farther from the planet mesh, it’s still doing this!
I must be missing something fundamental. Can anyone help figure out what’s going wrong with these functions?