Top Down Collision Detection and Reaction
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Top Down Collision Detection and Reaction
Hello. I'm sure this "problem" has been solved somewhere, but I just can't find it anywhere (yes, I searched with google also directly in the love2D forum). I'm pretty new to game programming and I tryed everything I could think of, but it is still not working right. In my last attempt (which I've attached) collision only works right with the top panels (which is buggy sometimes).
- Attachments
-
TDS.love
- (1.97 KiB) Downloaded 152 times
Re: Top Down Collision Detection and Reaction
Hey, I would recommend bump.lua, thread: viewtopic.php?f=4&t=78729&hilit=how+to+use+bump.lua
also: viewtopic.php?f=5&t=78086&hilit=bump.lua
I tried to code collision like this as well, hard stuff.
also: viewtopic.php?f=5&t=78086&hilit=bump.lua
I tried to code collision like this as well, hard stuff.
Re: Top Down Collision Detection and Reaction
Hmm.. I wanted to create my own collision system, but if it's really hard then I better try my luck with a library. Just to be sure, if one day I wanted to use my game for commercial use, can I still do it even if I used bump?
Re: Top Down Collision Detection and Reaction
I think so, in here: https://github.com/kikito/bump.lua I guess there is an answer, otherwise ask Kikito here on the forum.
Also don't count my word as the last, I tried making a collision system however i'm kinda of a rookie and I'm sure some user here has the advice you seek.
Also don't count my word as the last, I tried making a collision system however i'm kinda of a rookie and I'm sure some user here has the advice you seek.
Re: Top Down Collision Detection and Reaction
bump.lua is licensed under the MIT License, like most things LÖVE-related are.Bindie wrote:I think so, in here: https://github.com/kikito/bump.lua I guess there is an answer, otherwise ask Kikito here on the forum.
Also don't count my word as the last, I tried making a collision system however i'm kinda of a rookie and I'm sure some user here has the advice you seek.
So yes, you can, but you need to keep the MIT license around and enable user to see bump.lua is licensed under it.Copyright (c) 2012 Enrique García Cota
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
s-ol.nu
Code: Select all
print( type(love) )
if false then
baby:hurt(me)
end
Re: Top Down Collision Detection and Reaction
I can't look at your code right now but collision resolution for problems like this isn't that hard.
Imagine you have a function that you made, that can detect if a point is colliding with the world. This function will be called colWorld(x,y). I'll be using pseudocode.
Ok. From here you'll be able to do just about every type of world to object collision you'll ever need in a beginners 2D game like this. All you have to do is implement a function like this.
So from here, how do we apply this to your box game? If your box is 50x50, with the origin at the top left, this is how.
Rinse and repeat for every direction. You can do this more elegantly, but for now lets look at it like this. If up is being pressed, move the box up. If you detect a collision at the top of the box at 2 different points, move the box down by 1 pixel. We have 2 points for the 2 corners of the box. Why are the corners at (3,0) and (47,0)? Because if the box is ALSO moving to the right or left, we need a buffer for the horizontal movement. We'd need to add more points to detect if the box is wider than the smallest object in the world. But that's ok, your colWorld function should be fast enough to be called hundreds of times per frame without slowdown.
If this makes any sense let me know. I can always come back and clarify when I have an opportunity to open your love and look at your code.
Imagine you have a function that you made, that can detect if a point is colliding with the world. This function will be called colWorld(x,y). I'll be using pseudocode.
Code: Select all
function colWorld(x,y)
if(this point is touching the world) then
return true
end
return false
end
So from here, how do we apply this to your box game? If your box is 50x50, with the origin at the top left, this is how.
Code: Select all
function updateBox()
if upIsPressed then
box.y = box.y - 2
while colWorld(box.x+3, box.y) or colWorld(box.x+47, box.y) then
box.y = box.y+1
end
end
If this makes any sense let me know. I can always come back and clarify when I have an opportunity to open your love and look at your code.
- Jasoco
- Inner party member
- Posts: 3728
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Top Down Collision Detection and Reaction
I would definitely second the Bump recommendation. It'll save you a lot of frustration and let you just make the game and focus on the rest.
Re: Top Down Collision Detection and Reaction
A while ago I wrote something that looks a lot like your demo.
But yeah, you probably want to go with bump or hardon collider.
But yeah, you probably want to go with bump or hardon collider.
Re: Top Down Collision Detection and Reaction
Thank you all! I decided to use bump this time, but later, when I have more time I'll definetly try to code my own collision system mainly with help of ivan's tutorial.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 4 guests