Obtaining body by point.

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
Fab1can
Prole
Posts: 7
Joined: Sat Nov 07, 2015 5:58 pm
Location: Italy

Obtaining body by point.

Post by Fab1can »

How can i obtain a body by a point? if there is a body of 100x100 in 250,300 how can i obtain it with the point 280,310 (for example)?
User avatar
Murii
Party member
Posts: 216
Joined: Fri Jul 05, 2013 9:58 am
Location: Arad, Romania
Contact:

Re: Obtaining body by point.

Post by Murii »

Fab1can wrote:How can i obtain a body by a point? if there is a body of 100x100 in 250,300 how can i obtain it with the point 280,310 (for example)?
You mean the coordinates or what exactly?
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Obtaining body by point.

Post by Beelz »

I'm not sure if this is what you mean, but this is a way to identify when an object is inside a designated region.

Controls:
WASD - Green Block
D-Pad - Red Block
Attachments
region.love
(1.36 KiB) Downloaded 93 times

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Obtaining body by point.

Post by pgimeno »

By "body" do yo mean a physics body?
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Obtaining body by point.

Post by ivan »

First you do a query and this will give you a list of fixtures.
https://love2d.org/wiki/World:queryBoundingBox

Then you iterate the list and use "testPoint" on each fixture.
https://love2d.org/wiki/Fixture:testPoint

Last you get the associated body for each fixture.
https://love2d.org/wiki/Fixture:getBody
Fab1can
Prole
Posts: 7
Joined: Sat Nov 07, 2015 5:58 pm
Location: Italy

Re: Obtaining body by point.

Post by Fab1can »

ivan wrote:First you do a query and this will give you a list of fixtures.
https://love2d.org/wiki/World:queryBoundingBox

Then you iterate the list and use "testPoint" on each fixture.
https://love2d.org/wiki/Fixture:testPoint

Last you get the associated body for each fixture.
https://love2d.org/wiki/Fixture:getBody
Maybe this is what i want to do, but queryBoundingBox doesn't give me a list of fixtures.
EDIT:
I need something like a OnClick function for a body (love.physics.body).
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests