Collision Library Without The Physics

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Baggef
Prole
Posts: 18
Joined: Fri Aug 23, 2019 7:30 pm
Location: USA
Contact:

Collision Library Without The Physics

Post by Baggef » Sun Sep 01, 2019 12:03 am

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:
Attachments
boxColliderExample.love
(4.35 KiB) Downloaded 64 times
gaeem defelpmint is maiy pashin
Itch: Freakman
Twitter: baggefArt

User avatar
ivan
Party member
Posts: 1524
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collision Library Without The Physics

Post by ivan » Sun Sep 01, 2019 6:30 am

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!

User avatar
Baggef
Prole
Posts: 18
Joined: Fri Aug 23, 2019 7:30 pm
Location: USA
Contact:

Re: Collision Library Without The Physics

Post by Baggef » Sun Sep 08, 2019 10:31 pm

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.
gaeem defelpmint is maiy pashin
Itch: Freakman
Twitter: baggefArt

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Hydrogen Maniac and 5 guests