Collision Triggering without Dynamic object?

Hi!
I’m brand new on Defold, also on Lua, I lookup the forums and other tutorials to try to do so but was unsucessful.
My main goal was to make my Sprite.Image changes when my Llama walk in the water tile, could really find a way to do it with the tiles, I just added a collision box with the Trigger property.

Here is way I’ve done by now.
Added the collision box to my character, 1st problem (I can’t put Dynamic because it needs a mass and breaks my top-down moving system.)

Added the Trigger Box on the water.

And my script, wich I just pat a IO message so the console just tell me if the character actually touches
trigger box.

From this, nothing actually happens. The console doesn’t show me any sign on collision or whatever.

I thank you for the time you’ll take to answer this probably stupid question. Thanks again and have a great day :smiley:

You most likely need to be using static instead of trigger for the water. Here is a working example

TopDownBox2d.zip (3.8 KB)

Also you can define tiles in your tilemap as collision groups instead of manually placing collision objects.

3 Likes

Amazing! Thank you so much :smiley: :sunny:

1 Like

Here’s how you define collision groups in your tilesource. First you select your tileset as the collision file (or you can use any image with transparency as long as the tiles are at the same spot as what they are supposed to represent in terms of collision), then you can select and paint the groups into your tiles. So in this image I have the ground as default collision group and water as water collision group.

Then on the GO you added your tilemap to you create a collisionobject and set its shape to the tilesource. You will also want to make sure you set the mask to what you need, the group will be set by what you have in the tilesource.

Updated with tilemap

TopDownBox2d.zip (5.4 KB)

You can of course use layers too if you want to have some collision groups not associated with tile images but want to be able to paint freely you would use a transparent tile along with a solid (or whatever shape) collision image pair. There are other solutions too.

4 Likes

Thank you so much for the tutorial! I can’t find better! !

everything works fine but the tile blocks my character now, is there any way to fix it?

Nevermind! I fixed it by switching to Trigger!

1 Like

Is your character kinematic? You need to make sure you are colliding with the correct groups only. Check the group of the other and you should be able to tell the difference between walls and water.

dope%20water
thank you! here’s what I’ve done with your help :slight_smile:

9 Likes

Looking good!

I forgot that you can hide layers. Hidden layers will also not be drawn when the engine is running, but their collision groups will still be used. So you can use symbols to define areas too with this.

1 Like