Page 1 of 1

Collision Help?

Posted: Thu Jan 29, 2009 4:41 pm
by Pawnda
Hi. i am currently making my first game with love. its a breakout clone.
But the collision doesent work...
i have done exactly the same as in my test games...
but i don't see the problem with the code...

Re: Collision Help?

Posted: Thu Jan 29, 2009 4:53 pm
by Pawnda
hmm... i uploaded the wrong version... heres the right one...

Re: Collision Help?

Posted: Thu Jan 29, 2009 7:04 pm
by osuf oboys
Pawnda wrote:Hi. i am currently making my first game with love. its a breakout clone.
But the collision doesent work...
i have done exactly the same as in my test games...
but i don't see the problem with the code...
Hi, when something goes amiss, it's always useful to simplify the program, remove assumptions, or as many recent changes as possible so to get a program that works again. Once you have a case that works, you can work out precisely where your case breaks down and modify the original version of the program. You could for instance take the collision detection demo and change yours back to that as to make it as close as possible (or gradually go from that version to your version). If you give up, I can tell you what the problem is, but you'll lose a salmon.

Also, I believe it is advisable to create each block as its own table, with body, shape, and other properties, all stored in a blocks table rather than a matrix that specifies particular positions. This would also result in making it easier with e.g. dropping tiles. I would recommend that you store the tiles as keys however, not as values. That is, blocks[myblock] = true to add and blocks[myblock] = nil to remove.

There is a limitation in how fast objects can move. Increasing the velocity won't fix this. If you want things to move faster, you need to update the world update 'delta' by some value.

Re: Collision Help?

Posted: Thu Jan 29, 2009 8:40 pm
by Pawnda
Thanks alot ;-)

Re: Collision Help?

Posted: Fri Jan 30, 2009 8:12 am
by rude

Code: Select all

-- Probably wrong (offset [150,270]):
ballShape = love.physics.newCircleShape(ball,150,270,5)
-- Probably better (offset [0,0]):
ballShape = love.physics.newCircleShape(ball,5)

-- Also, you don't want zero mass on the ball. That will make it "terrain":
ball = love.physics.newBody(world, 0, 0, 0)
-- Better:
ball = love.physics.newBody(world, 0, 0)

Re: Collision Help?

Posted: Fri Jan 30, 2009 11:04 am
by osuf oboys
rude wrote:

Code: Select all

-- Probably wrong (radius=150):
ballShape = love.physics.newCircleShape(ball,150,270,5)
-- Probably better (radius=5):
ballShape = love.physics.newCircleShape(ball,5)
The constructor is overloaded - 150, 270, 5 creates a circular shape of radius 5 with an offset of (150,270) from the body. In other words, if the body is at (0,0), then the shape is at (150,270). This was also pawnda's problem, the collision detection was made at (150,270) but the drawing at (0,0). The same applied for the rectangular pad.
rude wrote:

Code: Select all

-- Also, you don't want zero mass on the ball. That will make it "terrain":
ball = love.physics.newBody(world, 0, 0, 0)
-- Better:
ball = love.physics.newBody(world, 0, 0)
Oh, I see, the default mass is 1 in the latter case. He was calling setMassFromShapes() afterwards though and static is equivalent to 0 mass, so that still worked out.

Re: Collision Help?

Posted: Fri Jan 30, 2009 11:11 am
by rude
My bad @ radius. Edifixed.

Not sure if setMassFromShapes does anything if the initial mass is 0. I think there's a separate list for terrain geometry (or was that Chipmunk?).

Re: Collision Help?

Posted: Fri Jan 30, 2009 12:12 pm
by osuf oboys
rude wrote:My bad @ radius. Edifixed.

Not sure if setMassFromShapes does anything if the initial mass is 0. I think there's a separate list for terrain geometry (or was that Chipmunk?).
I tried initializing with 0 mass and calling setMassFromShape - no longer isStatic.
I tried initializing with a non-zero mass and setting to 0 - became isStatic.

Re: Collision Help?

Posted: Fri Jan 30, 2009 12:17 pm
by rude
Cool. I guess it was Chipmunk, then. :ultraglee: