STI and collision

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ZephB
Prole
Posts: 3
Joined: Fri May 01, 2020 11:09 pm

STI and collision

Post by ZephB » Fri May 01, 2020 11:17 pm

Hi,
I have really searched around the Internet to know how to have simple collisions working with my little game. I want to use STI because it's so simple to implement, but how to make simple collisions without using box2d? If this subject is already well responded can you guys refer me to the topic, because right now I'm a little bit strugling. I'm coming form pico-8 so all of this is new to me

User avatar
JuanjoSalvador
Prole
Posts: 24
Joined: Wed Nov 27, 2019 9:19 pm
Location: Almeria, ES
Contact:

Re: STI and collision

Post by JuanjoSalvador » Fri May 01, 2020 11:56 pm

It's funny, I switched from Love2D to PICO-8 few years ago, and then back to Love2D again.

I think I already answered this on Reddit too, but in a nutshell, using Box2D plugin is your best choice, imho. If you don't need gravity, you can set gravity to 0 when creating the World object.
itch.io profile - When I'm uploading my works and devblogs
GitHub - All my code is here!
Horchata - A set of Lua modules I wrote to make some task easier

ZephB
Prole
Posts: 3
Joined: Fri May 01, 2020 11:09 pm

Re: STI and collision

Post by ZephB » Sat May 02, 2020 12:22 am

Honestly that's funny because 2 years ago I tried love2d found it too complicated and then switched to pico-8 ha ha ha. Should I draw the tilemap myself, would it be easier for me to test collisions?

User avatar
pgimeno
Party member
Posts: 2211
Joined: Sun Oct 18, 2015 2:58 pm

Re: STI and collision

Post by pgimeno » Sat May 02, 2020 11:15 am

For axis-aligned rectangles (AABBs), I recommend the Bump library, https://github.com/kikito/bump.lua

STI contains a plugin for bump, no idea how they're used together though. I haven't used STI myself.
Last edited by pgimeno on Sat May 02, 2020 12:13 pm, edited 1 time in total.

User avatar
JuanjoSalvador
Prole
Posts: 24
Joined: Wed Nov 27, 2019 9:19 pm
Location: Almeria, ES
Contact:

Re: STI and collision

Post by JuanjoSalvador » Sat May 02, 2020 12:06 pm

ZephB wrote:
Sat May 02, 2020 12:22 am
Should I draw the tilemap myself, would it be easier for me to test collisions?
Depending of the complexity of your tileset, but I would say no. Can you provide a .love file or something we can see?
itch.io profile - When I'm uploading my works and devblogs
GitHub - All my code is here!
Horchata - A set of Lua modules I wrote to make some task easier

ZephB
Prole
Posts: 3
Joined: Fri May 01, 2020 11:09 pm

Re: STI and collision

Post by ZephB » Sat May 02, 2020 4:44 pm

JuanjoSalvador wrote:
Sat May 02, 2020 12:06 pm
ZephB wrote:
Sat May 02, 2020 12:22 am
Should I draw the tilemap myself, would it be easier for me to test collisions?
Depending of the complexity of your tileset, but I would say no. Can you provide a .love file or something we can see?
Actually I have found the perfect solution. The cartographer library! It is capable of doing the same thing as what pico-8 is capable, it's really great. I've had somme issues so I created my own function in cartographer that allow me to quickly put a map, a tile_number and a property and that returns true or false, exactly like fget in pico-8. I'm really happy with it. This is what I added :

Code: Select all

function pget(map,gid,propertyName)
    local prespect
	if gid == false or gid == nil then
		prespect = false
		return false
	else
		prespect = map:getTileProperty(gid,propertyName)
		if prespect then
			return true
		else
			return false
		end
	end
end

User avatar
JuanjoSalvador
Prole
Posts: 24
Joined: Wed Nov 27, 2019 9:19 pm
Location: Almeria, ES
Contact:

Re: STI and collision

Post by JuanjoSalvador » Sat May 02, 2020 5:36 pm

Perfect :)
itch.io profile - When I'm uploading my works and devblogs
GitHub - All my code is here!
Horchata - A set of Lua modules I wrote to make some task easier

cristoferfb
Prole
Posts: 16
Joined: Wed May 15, 2019 12:41 am
Location: Valparaiso, Chile.

Re: STI and collision

Post by cristoferfb » Sun May 03, 2020 5:03 am

Love2D documentation have a nice list of tutorials:

https://love2d.org/wiki/Category:Tutorials

The first in the list have a very nice explication about 2D collisions:

https://sheepolution.com/learn/book/13

It have too a very compressive introduction to tiles and collisions:

https://sheepolution.com/learn/book/18

U can learn it and then implement a solution for ur problem, love requiere a little more work than PICO but the flexibility is certainly bigger. The documentation is your best friend in any code adventure✌️.

User avatar
kuzika
Prole
Posts: 14
Joined: Tue Apr 21, 2020 3:58 pm

Re: STI and collision

Post by kuzika » Tue May 05, 2020 9:27 pm

Wow this really helped me a lot. Thanks 😀
"kuzika" literally means "to burry"

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests