Page 1 of 1

Obtaining body by point.

Posted: Thu Nov 19, 2015 6:31 pm
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)?

Re: Obtaining body by point.

Posted: Thu Nov 19, 2015 6:46 pm
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?

Re: Obtaining body by point.

Posted: Thu Nov 19, 2015 9:14 pm
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

Re: Obtaining body by point.

Posted: Thu Nov 19, 2015 10:25 pm
by pgimeno
By "body" do yo mean a physics body?

Re: Obtaining body by point.

Posted: Fri Nov 20, 2015 5:52 am
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

Re: Obtaining body by point.

Posted: Sat Nov 21, 2015 1:38 pm
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).