löve newbie has some questions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Posts: 6
Joined: Sat Oct 17, 2009 9:28 pm

Re: löve newbie has some questions

Post by OUT »

what kind of collision?
i am just asking, because if you want to register a collision, i am not sure how to do that yet
if you just want your game objects to collide, I can help in that.
In that case you just have to create a physics world first, then create bodies in that and attach shapes to those.
If you did the steps properly here, you can forget about the colliding, because the physics engine will take care of it.

So create a physics world with world= love.physics.newWorld(w,h)

Add bodies body1= love.physics.newBody(world, x, y)
body2=love.physics.newBody(world, x, y)

You have to know, that bodies store the velocity, spin, momentum etc. If you want a dynamic object, whom forces apply to and world gives it acceleration, you have to give the body mass value. If you dont give a mass value, it's a STATIC body. Forces don't apply to static bodies, two static bodies won't collide, BUT a dynamic body and a static can. The dynamic body will smash into the static one but the static one won't move, still the dynamic will bounce back etc.
Static bodies are generally made as the immovable objects such as the ground, the boundaries of the gamefield etc.

Third phase, adding shapes to the bodies:
shape1=newCircleShape(body1, radius)
shape2=newPolygonShape(body2, coordinate pairs of the vertexes)

The attached shapes you add to the bodies provide the collision and mass center informations to the physics world.
You can add many shapes to 1 body, for example you can make a monster in armor, there would be a monster shape and an armor shape which would be bigger.
If there are many static objects in your game, it's smart to make one static body (so don't set its mass value) and attach all the static objects to it as shapes.
That way at loading you can work with it as a single body.

CHECK OUT the lovelanche example that comes with löve. It is in the demo library.
User avatar
Posts: 15
Joined: Wed May 20, 2009 8:29 pm
Location: Blowin' Green, O'Hi-o

Re: löve newbie has some questions

Post by F687/s »

Does anyone have a simple example of basic collision? I just need something to give me an idea of how it works, so I kind implement it into my own code.
From the examples wiki:

Code: Select all

function colide(x1,y1,width1,height1,x2,y2,width2,height2)
    return not ( 
        (x2 > (x1 + width1 )) or
        (x1 > (x2 + width2 )) or
        (y2 > (y1 + height1)) or
        (y1 > (y2 + height2)) )
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 25 guests