Collision Help?

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
Pawnda
Prole
Posts: 8
Joined: Thu Jan 29, 2009 4:34 pm

Collision Help?

Post 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...
Attachments
Breakout.love
(48.1 KiB) Downloaded 195 times
Pawnda
Prole
Posts: 8
Joined: Thu Jan 29, 2009 4:34 pm

Re: Collision Help?

Post by Pawnda »

hmm... i uploaded the wrong version... heres the right one...
Attachments
Breakout.love
(48.1 KiB) Downloaded 203 times
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Collision Help?

Post 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.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Pawnda
Prole
Posts: 8
Joined: Thu Jan 29, 2009 4:34 pm

Re: Collision Help?

Post by Pawnda »

Thanks alot ;-)
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Collision Help?

Post 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)
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Collision Help?

Post 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.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Collision Help?

Post 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?).
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Collision Help?

Post 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.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Collision Help?

Post by rude »

Cool. I guess it was Chipmunk, then. :ultraglee:
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests