Collision between non-physics object and a physics object

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
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Collision between non-physics object and a physics object

Post by Ducktor Cid » Tue Oct 18, 2016 9:59 pm

I have a pot that is creating using love.physics and a player that is a love.graphics rectangle, can I use a regular bounding box collision detection to see if they collide and can I use a library/module like Hardon Collider or bump.lua for it?

code for checking player collision (taken from wiki and edited):

function pot:CheckCollisionWithPlayer(pX,pY,pW,pH)
return pot.Position.x < pX+pW and
pW < pot.Position.x+pot.Size.x and
pot.Position.y < pY+pH and
pH < pot.Size.y+pH
end

I usually get confused with stuff like x1 and x2 because I don't know which one to put in the variables. The function about always returns false no matter what

User avatar
pgimeno
Party member
Posts: 1227
Joined: Sun Oct 18, 2015 2:58 pm

Re: Collision between non-physics object and a physics object

Post by pgimeno » Wed Oct 19, 2016 3:00 am

It's all about what positions you're using. A full .love file would help. The collision function alone is not enough to know what's going on.

About x1 and x2, it doesn't matter, because if A collides with B, then B collides with A too.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

User avatar
ivan
Party member
Posts: 1313
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collision between non-physics object and a physics object

Post by ivan » Wed Oct 19, 2016 5:17 am

Ducktor Cid wrote:I have a pot that is creating using love.physics and a player that is a love.graphics rectangle, can I use a regular bounding box collision detection to see if they collide
love.physics provides you with so much more sophisticated collision detection so this is not something you should ever do.
It's also bad design to mix collision and rendering code - you want to keep these two 'decoupled'.
So generally I would recommend studying the love.physics/box2d api, it has hundreds of functions.
Some of the more relevant ones are:
World:queryBoundingBox - can provide potentially overlapping fixtures
World:rayCast/Fixture:rayCast/Shape:testSegment - ray cast tests
Fixture:testPoint/Shape:testPoint - point tests
Fixture:getBoundingBox/Shape:getBoundingBox/Shape:computeAABB

In short, there is no point in using love.physics if you are going to check for collisions manually.
And the code is more complicated when rotation is involved.

Post Reply

Who is online

Users browsing this forum: drikdrok and 4 guests