hi!
is there any way to check which side of a rectangular body is being collided with? im not actually using love.physics in my project, im using an old-skool rectIntersect() function, but im having no joy with the maths(ive got it sort of working, but it needs to be pretty much perfect). is there a way of doing this with physics?
thanks.x
rectangular body help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: rectangular body help
Well, I'd say that if the colliding object is above the base object it's colliding with the top, if it's below it's colliding with the bottom, etc.
Re: rectangular body help
That doesn't work if it'd been rotated though.
If you need need need this you could always construct the rectangle of lines and use each of their callback data's to feed into an overall collide function.
If you need need need this you could always construct the rectangle of lines and use each of their callback data's to feed into an overall collide function.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: rectangular body help
ok, i dont think im gonna use the physics module for this. this is the code im using:
(this is from the OOP class i made for a rect-based collision system, self refers to one rect, anotherRect to the second)
works most of the time, but it needs to work all of the time.
any holes in this that anyone can spot?
x
Code: Select all
local xOff = self.x + anotherRect.x + (anotherRect.width / 2)
local yOff = self.y + anotherRect.y + (anotherRect.height / 2)
if(xOff > yOff) then
if(self.x <= (anotherRect.x + (anotherRect.width / 2))) then return Left end
if(self.x >= (anotherRect.x + (anotherRect.width / 2))) then return Right end
else
if(self.y <= (anotherRect.y + (anotherRect.height / 2))) then return Up end
if(self.y >= (anotherRect.y + (anotherRect.height / 2))) then return Down end
end
works most of the time, but it needs to work all of the time.
any holes in this that anyone can spot?
x
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: rectangular body help
I think you need to do this: (I also removed superfluous parentheses)hertzcastle wrote:ok, i dont think im gonna use the physics module for this. this is the code im using:
Code: Select all
local xOff = math.abs(anotherRect.x + anotherRect.width / 2 - self.x) -- subtracting here, because it's about the difference!
local yOff = math.abs(anotherRect.y + anotherRect.height / 2 - self.y) -- same here. also note the math.abs() call, this is to ensure xOff and yOff have the same sign
if(xOff > yOff) then
if self.x <= anotherRect.x + anotherRect.width / 2 then return Left end
return Right
else
if self.y <= anotherRect.y + anotherRect.height / 2 then return Up end
return Down
end
Help us help you: attach a .love.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: rectangular body help
wow, yes!
much, much smoother! thanks rude!
now i can get on with the next million gameplay elements!
x
---DOUBLE POST---
and yeah, too much parenthesis. i come from a world of java, thats all i can say
xx
much, much smoother! thanks rude!
now i can get on with the next million gameplay elements!
x
---DOUBLE POST---
and yeah, too much parenthesis. i come from a world of java, thats all i can say
xx
Last edited by bartbes on Sun Jun 13, 2010 8:59 am, edited 1 time in total.
Reason: Double post....
Reason: Double post....
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: rectangular body help
It's Robin. But you're welcome.hertzcastle wrote:thanks rude!
Poor thing.hertzcastle wrote:and yeah, too much parenthesis. i come from a world of java, thats all i can say
Help us help you: attach a .love.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: rectangular body help
sorry dude, meant to type Robin
big thanks!
big thanks!
Re: rectangular body help
So why not use the physics module and create a rectangular collision system? Is there a factor of the love.physics module that makes it slower then such a system? Or did you simply want to write a rectangular collision system for fun?
Good bye.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: rectangular body help
@luiji:
basically, i just wanted to set up something really simple and reusable. i find the physics stuff really good, but not really suited to what im doing at the moment. i guess im old fashioned and just want a list(table) of rectangles to iterate over. But some day I'm going to figure out the love.physics stuff, some day...
but yea, i dont really need "physics" as such, just collisions, usually find it a bit quicker to write my own stuff, this has obv been a bit of an exception ...
x
basically, i just wanted to set up something really simple and reusable. i find the physics stuff really good, but not really suited to what im doing at the moment. i guess im old fashioned and just want a list(table) of rectangles to iterate over. But some day I'm going to figure out the love.physics stuff, some day...
but yea, i dont really need "physics" as such, just collisions, usually find it a bit quicker to write my own stuff, this has obv been a bit of an exception ...
x
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests