# ClosestPointOnBounds problem

**URL:** https://discussions.unity.com/t/closestpointonbounds-problem/400797
**Category:** Physics
**Created:** [November 3, 2009, 12:31pm UTC](https://discussions.unity.com/t/closestpointonbounds-problem/400797 "2009-11-03T12:31:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_14294729](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon\_14294729](https://discussions.unity.com/u/anon_14294729)
#### Post date: [November 3, 2009, 12:31pm UTC](https://discussions.unity.com/t/closestpointonbounds-problem/400797/1 "2009-11-03T12:31:14Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![andeeeee](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@andeeeee](https://discussions.unity.com/u/andeeeee)
#### Post date: [November 4, 2009, 11:56am UTC](https://discussions.unity.com/t/closestpointonbounds-problem/400797/2 "2009-11-04T11:56:11Z")

</div>

> [@""](#):
>
> Ahoy Unityers!

Personally, I think of myself as a _Unitoid_, but no matter 😉

[Collider.ClosestPointOnBounds](http://unity3d.com/support/documentation/ScriptReference/Collider.ClosestPointOnBounds.html) returns the closest point on the collider’s bounding box, which could be a fair distance from the object’s surface, depending on its shape. If your target object has a MeshCollider, you may be able to use a [linecast](http://unity3d.com/support/documentation/ScriptReference/Physics.Linecast.html) to get the exact point of contact on the mesh surface. The start and end of the line would be the projectile’s and target’s transform.position values, respectively.
