Contact_point_response distance isn't always positive

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

Hmm, good question. @sven, any input?

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?

1 Like

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:

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.