How to write a simple query world using love.physics?
Posted: Sat Feb 22, 2025 5:09 pm
I'm trying to use vanilla love.physics (box2d) but I could't find a direct function to query a specific region (circle, rectangle etc.). There is one function named World:queryBoundingBox() but I can't figure out how to use this. Ultimately, I want to query a circular area in front of the player and return the object class in that query area. I'm using STI to import Tiled levels. I have set the class names of relevant colliders inside Tiled (for bushes, chest etc.) and I want to retrieve this data from my query function. Can someone help me write a simple function for this using only love.physics? My progress on the function so far is this,
Code: Select all
local function Player:queryWorld()
-- Spawn a query collider on player
local query_collider = love.physics.newCircleShape(self.x, self.y, 50)
query_collider:setSensor(true)
-- List to store all the colliders
local inside_query = {}
-- Collider classes: TODO
end