True Tile Collision

Sorry if not the right spot for the post!
From what I’ve seen, no one has done a collision using data from tilemap. Since I’ve done a similar thing in Gamemaker except I had to use objects on level start to create “tilemap” with indexes of necessary tiles.
I’m in the very beginning of developing this system and I’m learning Defold & LUA so I wanted to combine it under a journey of learning Defold “video series”. First one is here but it also shows one bug I encountered and I don’t know if I should make new Question post or I can discuss problems here.


EDIT: For my code bug I kinda sorted right side collision, but the left is still problematic.
6 Likes

Please post your specific question in a forum post. We’re happy to help!

2 Likes

@britzl I got it fixed myself. Coordinates starting from 1 instead of 0 throws off bitwise calculations and I couldn’t get it working, so I had to use regular calculation for snapping to tile side.

3 Likes

I made progress update in video format:

5 Likes

True Tile Collision is heading on the finish line for publishing on asset portal. Meanwhile, you have a chance to test HTML5 build on itch.io.
You can actually get LUA module dependency HERE (I hope it’s set up right) and example project HERE.

At the moment I was concentrating for slope platformer functions and left base ones as I was deriving from them. But I think they are easy to understand and modular to put together top-down movement and non-slope platformer.

Update from the previous update:
Added ledge collision (catch on the ledge);
Speed normalization for slopes;
Added flags for useful event triggering :

 	--TRIGGERS					--Useful for triggering animations or states
	inst.landed		  	--True when happens collision with ground
	inst.ledge_trig   	--True for first frame ledge is grabbed
	inst.wallslide_trig 	--True for first frame wallslide is triggered
	inst.wall_trig	  --True when wall collision is triggered			(useful for enemy to turn around)
	inst.cliff_trig	  	--True when cliff edge collision is triggered	(useful for enemy to turn around)
	inst.fast_fall	  --True if falling is at max speed
2 Likes

I managed to cling on to the edge in the example:

I kept hanging there without having any buttons pressed. And I could only move if I jumped first.

3 Likes

That’s the “Ledge collision”. It only catches the ledge if you pressing in that direction. It is it’s own physics update “module”, so makes easier to strip out if game doesn’t need it.
For now it bypass collision if you press down and that’s the way to let go the ledge. Feel free to take a look in LUA module for physics.
At the moment whole physics is as if all features are active but it’s really easy to tweak especially someone like you. And I’ve made functions that makes easy to make your own physics behavior modules.
I’m planning to either decouple wallslide behaviour in it’s own function or put toggle variable for that and same for other non-barebone features.

2 Likes

Cool, got it!

1 Like

Got to say I programmed everything like I’d do that in C style language, so I’m wondering if doing that with tables makes it more efficient instead of manipulating object instances variables?

Can you show an example of what you mean?

2 Likes

I don’t really have imagination for good example that have good use of LUA, but what I do is pass self to functions to create variables inside instance or manipulate them:

function h_move(inst)
	local hin = inst.xinput														--xinput set in get_xinput()
	local hsp = inst.spd.x
	if hin ~= 0 then															--Move
		hsp = hsp + hin * inst.ACC
		hsp = clamp(hsp, -inst.MAX, inst.MAX)
	else																		--deaccelerate
		hsp = approach(hsp, 0, inst.DCC)										--(value, goal, ammount)
	end
	inst.spd.x = hsp
end

Yeah, that sounds good.

1 Like

I’m thinking to rename these flags to have most convenient names. Any suggestions?

Been a bit busy but kept tinkering and now up to last struggle to reach the last mile to the finish.
I have introduced platformer essential thing - moving platforms, but I have a small problem with collision.
After that, I’m wrapping up building blocks for top-down movement and platformer without slope collision.

Playable demo on itch, example project & lua module on github are updated.
Now there’s 3x examples (block platformer, platformer using slopes and top down movement).

2 Likes

So right before creating the Asset portal page, I created brief READ ME to explain how easy it is to add the TTC to the game.

Hey this is really cool!
Is this faster than just using a few collision shapes and physics? I usually use 2 collision shapes for the player 1 for the feet and 2 for the head so if I’m crouching I can disable the head collision shape.

This is more like retro physics, super fast to set up for that - think NES games and not far from that.
Right now there’s nothing to work for automatic crouching, but if you have some knowledge and willing to check code it’s not that hard to create such behavior. At the moment you can use set_hitbox to set different hit box size when player wants to duck.

Looks good!

If I may make 2 suggestions;

  1. move tile types for set tiles to its own file and return so these can be easily modified.
  2. provide half tile collision (horizontal and vertical)
  1. I’m weak at using Lua and generally with Defold, set_tiles just change values in lua module local variables that hold ID of tilesource to look for a collision. Sounds like you are able to do it yourself.
  2. It’s doable of course, but change the whole collision checking fundamentally. At that point, it’s better to use smaller tile size.
    THIS is the type of games I had in mind when I developed the collision system.