World:queryBoundingBox not finding any fixtures

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheHUG
Citizen
Posts: 61
Joined: Sun Apr 01, 2018 4:21 pm

World:queryBoundingBox not finding any fixtures

Post by TheHUG »

Hi!
I'm trying to use World:queryBoundingBox(), but it doesn't seem to find anything. using windfield's query functions does work, and though I can't tell what I'm not doing that they are, I can't get it to work for myself. a minimal example is:

Code: Select all

function love.load(arg)
   midx = love.graphics.getWidth()/2
   midy = love.graphics.getHeight()/2

   w = love.physics.newWorld()
   bod = love.physics.newBody(w, midx, midy, 'dynamic')
   shp = love.physics.newCircleShape(midx, midy, 10)
   fix = love.physics.newFixture(bod, shp, 1)
   callback = function(fixture)
      print(fixture)
      return true
   end
   w:queryBoundingBox(midx +10, midy + 10, midx - 10, midy - 10 , callback)
end

function love.update(dt)
end

function love.draw()
end

I'd expect this to print at least one fixture, but it isn't printing anything. What am I doing wrong?
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: World:queryBoundingBox not finding any fixtures

Post by pgimeno »

The shape is relative to the body. Create the shape at 0, 0 instead of midx, midy and it will work. The way you're doing it, it's being created at 2*midx, 2*midy, and indeed, querying a bounding box centered at 2*midx, 2*midy reports it, but that doesn't seem to be what you're after.

Also, your bounding box limits are inverted, though that doesn't seem to matter for some reason.
TheHUG
Citizen
Posts: 61
Joined: Sun Apr 01, 2018 4:21 pm

Re: World:queryBoundingBox not finding any fixtures

Post by TheHUG »

Oh yeah whoops, that explains, thanks!

And yeah I posted the wrong version, I had inverted the points to see if I was putting them in the wrong way around and forgot to put it back for the example :P
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 27 guests