This is what currently have
local function handle_obstacle_contact(self, normal, distance, other_id)
if distance > 0 then
local proj = vmath.project(self.correction, normal * distance)
if proj < 1 then
-- Only care for projections that does not overshoot.
local comp = (distance - distance * proj) * normal
-- Apply compensation
go.set_position(go.get_position() + comp)
-- Accumulate correction done
self.correction = self.correction + comp
else
-- collided with a wall; change direction
if math.abs(normal.x) > .7 then
self.facing_direction = self.facing_direction * -1
end
end
end
-- collided with the ground. stop vertical movement
if normal.y > 0.7 then
self.ground_contact = true
self.velocity.y = 0
end
end
function on_message(self, message_id, message, sender)
if message_id == msg_contact_point_response then
-- check that the object is something we consider an obstacle
if message.group == group_obstacle then
handle_obstacle_contact(self, message.normal, message.distance, message.other_id)
end
end
end