Page 1 of 2
Collision detection in Löve?
Posted: Tue Jun 23, 2009 4:31 am
by Maholain
I was looking around the documentation and couldn't find anything on hit Tests or collisions? A search found nothing since the term 'collision' seem to be too common. Can anyone help me on how to create some form of collision detection?
Thanks!
Nice similes by the way
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 1:02 pm
by bartbes
You might want to check out the
docs on love.physics.
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 3:46 pm
by Maholain
So.. is this the only way to detect collision in Löve? Also, when I used the example on collision in the docs, and tried to add in a keypressed callback and later tried to place a love.keyboard in the update(dt) function, it threw me an error.
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 3:52 pm
by bartbes
It's not the only way, but it's the only way that you don't have to code yourself. About the error, it all depends on your code and what the specific error was.
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 5:02 pm
by Maholain
My error was main.lua:34: attempt to perform arithmetic on global 'x' (a nil value). I have attached the file below:
Anyways, since I don't really like using Box2d, are there any examples of programming a collision detection without using love.physics?
Thank you.
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 5:09 pm
by Robin
Maholain wrote:My error was main.lua:34: attempt to perform arithmetic on global 'x' (a nil value). I have attached the file below:
Code: Select all
if love.keyboard.isDown(love.key_right) then
x = x + (speed * dt)
elseif love.keyboard.isDown(love.key_left) then
x = x - (speed * dt)
end
Setting x doesn't really work if you have no variable called "x". Maybe you wanted to use GetX() and SetX()?
EDIT: tried [GS]etX(), and those work (to a certain extend). The variable "speed" is awfully high. Something else fishy seems to be going on here as well, but I have no clue what it is.
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 5:13 pm
by Maholain
Robin wrote:Maholain wrote:My error was main.lua:34: attempt to perform arithmetic on global 'x' (a nil value). I have attached the file below:
Code: Select all
if love.keyboard.isDown(love.key_right) then
x = x + (speed * dt)
elseif love.keyboard.isDown(love.key_left) then
x = x - (speed * dt)
end
Setting x doesn't really work if you have no variable called "x". Maybe you wanted to use GetX() and SetX()?
Ah, I keep automatically assuming x is a variable that is already present (like in Flash, etc).
Well, I have no idea to use getx or setx since the documentation has no search. Could anyone point me to that direction?
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 5:28 pm
by Robin
Maholain wrote:Well, I have no idea to use getx or setx since the documentation has no search. Could anyone point me to that direction?
Here you go:
http://love2d.org/docs/Body.html
http://love2d.org/docs/Body_getX_1.html
http://love2d.org/docs/Body_setX_1.html
(btw, I don't think setting the position directly is The Right Thing to do when it comes to moving objects.)
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 6:13 pm
by Maholain
Okay, but since setX and getX isn't used for moving objects, how could I get a way to move objects in my code example (look above a few posts)? Kinda confused here. Basically, if someone could upload an example with working movement, I'd be very happy and learn loads off of it!
Re: Collision detection in Löve?
Posted: Tue Jun 23, 2009 6:51 pm
by Sardtok
Have a look at the Body documentation posted above.
There are getters and setters for other physical attributes like velocity which might come in handy.