Page 1 of 1

Collision Library Without The Physics

Posted: Sun Sep 01, 2019 12:03 am
by Baggef
If you're looking for something with easy collision and no physics, such as a top-down game, you've come to the right place

A typical collider looks like this:

Code: Select all

--               x, y, width, height, tag, trigger
collider.newBox(100, 100, 250, 250, 'wall', false)
Read more and download here: https://github.com/Baggef/LoveCollider

There is some jank that I'm not capable enough to understand, so if you see anything wrong please tell me!

Here is an example of the library at work:

Re: Collision Library Without The Physics

Posted: Sun Sep 01, 2019 6:30 am
by ivan
Hello,
Writing your own collision system is an admirable attempt but it's hard and your code needs work.
For example, you need to use table.remove instead of:

Code: Select all

		for k,v in ipairs(collider.boxIDs) do
			if v == newBox.ID then
				v = nil
			end
		end
Request() takes your current movement incriments and your collider's ID and tests if that collider would be able to go there
Does this mean that you are simply checking if the future position is blocked or not? This would not work well with fast moving objects.
The "proper" way to do it is to find the shortest separation vector between the two intersecting shapes and move one of the shapes so that they no longer overlap.
I've made some tutorials in the past that you might find useful:
https://2dengine.com/?p=intersections
https://2dengine.com/?p=collisions
Good luck!

Re: Collision Library Without The Physics

Posted: Sun Sep 08, 2019 10:31 pm
by Baggef
ivan wrote: Sun Sep 01, 2019 6:30 am The "proper" way to do it is to find the shortest separation vector between the two intersecting shapes and move one of the shapes so that they no longer overlap.
Thanks! I will try this out, as you said I did find some problems with fast moving objects. I wanted to try to see if I could create my own as a little challenge to myself. I'm very new to lua and love2d and mainly work in C# with Unity so I'm not very used to writing physics stuff as that's usually taken care of already in unity.