problem about queryRegion

I want to use physics.queryRegion to detect physic body . It works well when the physic body is rect, but if it is a circle or irregular shape, the body will be hit even the hit point is outside the physic body.

-- the circle should be green because the query point is outside the physic body, but it's red now. local physics = require("physics") physics.start() local circle = display.newCircle(500, 500, 250) circle:setFillColor(0, 1, 0, 1) -- green physics.addBody(circle, "static", {radius = 250}) local rect = display.newRect(0, 0, 10, 10) rect:setFillColor(1, 1, 1, 1) rect:translate(circle.x - 250 +5 , circle.y - 250 + 5) local hits = physics.queryRegion(circle.x - 250, circle.y - 250, circle.x - 250 + 10, circle.y - 250 + 10) if (hits) then for i, v in ipairs(hits) do if v == circle then circle:setFillColor(1, 0, 0, 1) --red end end end

Hi @pickerel,

I’m not sure that I understand your scenario. The queried region is a rectangle, so if any part of any other object resides within that region, you’ll register a hit. Do you want to “query a circular region” or something like that? If so, then I suggest that you create another physics object (sensor, kinematic) and then check for collisions upon that object… effectively, it’s a “region” but you could make it any shape you want.

Take care,

Brent

I’ve solved this problem with rayCast + queryRegion.

thanks, Brent. 

Hi @pickerel,

I’m not sure that I understand your scenario. The queried region is a rectangle, so if any part of any other object resides within that region, you’ll register a hit. Do you want to “query a circular region” or something like that? If so, then I suggest that you create another physics object (sensor, kinematic) and then check for collisions upon that object… effectively, it’s a “region” but you could make it any shape you want.

Take care,

Brent

I’ve solved this problem with rayCast + queryRegion.

thanks, Brent.