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
Collision detection in Löve?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Collision detection in Löve?
You might want to check out the docs on love.physics.
Re: Collision detection in Löve?
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Collision detection in Löve?
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?
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.
Anyways, since I don't really like using Box2d, are there any examples of programming a collision detection without using love.physics?
Thank you.
- Attachments
-
- test.love
- (11.5 KiB) Downloaded 186 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Collision detection in Löve?
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
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.
Help us help you: attach a .love.
Re: Collision detection in Löve?
Ah, I keep automatically assuming x is a variable that is already present (like in Flash, etc).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:Setting x doesn't really work if you have no variable called "x". Maybe you wanted to use GetX() and SetX()?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
Well, I have no idea to use getx or setx since the documentation has no search. Could anyone point me to that direction?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Collision detection in Löve?
Here you go: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?
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.)
Help us help you: attach a .love.
Re: Collision detection in Löve?
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!
- Sardtok
- Party member
- Posts: 108
- Joined: Thu Feb 21, 2008 2:37 pm
- Location: Norway/Norge/諾威/挪威 (Yes, I'm teh back!)
- Contact:
Re: Collision detection in Löve?
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.
There are getters and setters for other physical attributes like velocity which might come in handy.
Take off every Zigg for great rapist.
Now, outgay that!
Now, outgay that!
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 2 guests