# Contact\_point\_response distance isn't always positive

**URL:** <https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359>\
**Category:** Questions\
**Created:** [May 28, 2019, 5:42pm UTC](https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359 "2019-05-28T17:42:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solarlune](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/solarlune/32/10299_2.png) [@solarlune](https://forum.defold.com/u/solarlune)\
**Post date:** [May 28, 2019, 5:42pm UTC](https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359/1 "2019-05-28T17:42:39Z")

</div>

Hey, there.

I’m trying to do some collision resolution for an overhead adventure game with a tile map, but am running into a few issues. I notice that the [documentation](https://www.defold.com/ref/physics/#contact_point_response:position-normal-relative_velocity-distance-applied_impulse-life_time-mass-other_mass-other_id-other_position-other_group-own_group) for contact\_point\_response’s distance field says it’s always positive. However, I’m finding that the distance is frequently negative; is this incorrect?

```
function on_message(self, message_id, message, sender)
    if message_id == hash("contact_point_response") then
	local newpos = go.get_position() + (message.normal * message.distance)
	print(message.distance)
	go.set_position(newpos)
    end
end

```

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2019, 7:43pm UTC](https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359/2 "2019-05-28T19:43:48Z")

</div>

> [@solarlune](#):
>
> However, I’m finding that the distance is frequently negative; is this incorrect?

Hmm, good question. @sven, any input?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 29, 2019, 7:22am UTC](https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359/3 "2019-05-29T07:22:15Z")

</div>

In physics engines, to prevent numerical instability issues, you can often find that they have “thick” planes. That is, you can get a collision when you’re sufficiently close to the surface, even if it’s on the “front” side of the plane.

That said, I’m not sure if Box2D has such a setting.

What’s the actual magnitude of the value you get back?

---

<div class="post-metadata">

**Author:** ![solarlune](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/solarlune/32/10299_2.png) [@solarlune](https://forum.defold.com/u/solarlune)\
**Post date:** [May 29, 2019, 3:18pm UTC](https://forum.defold.com/t/contact-point-response-distance-isnt-always-positive/53359/4 "2019-05-29T15:18:53Z")

</div>

Yeah, that’s true; it’s just inconsistent with the documentation, then.

As for the magnitude, it varies. The following is debug output from moving a 2D kinematic Game Object directly into a static body at a perpendicular angle and printing `message.distance` for each contact point response:

```lua
DEBUG:SCRIPT: -0.99999904632568
DEBUG:SCRIPT: 2.9999971389771
DEBUG:SCRIPT: 5.9604644775391e-06
DEBUG:SCRIPT: -0.99999904632568
DEBUG:SCRIPT: 2.9999971389771
DEBUG:SCRIPT: -5.9604644775391e-06
DEBUG:SCRIPT: -0.99999904632568
DEBUG:SCRIPT: 2.9999971389771
DEBUG:SCRIPT: 5.9604644775391e-06

```

From how the object jitters, this would seem to be in pixels.
