Question about handling triggers (SOLVED)

Hi everyone I am working on a top-down 2D game (made a post regarding enemy movement a few days ago) and I am trying to get some basic combat working. One solution I found was using triggers on the sword game object and detecting when the enemy enters it. That is working well enough for now but the next step was working on allowing the enemy to damage the player. I was going to use triggers for that as well but I am not sure how to mask those triggers to only certain types of game objects. I have a link to the GitHub repo here: GitHub - michaelFellows/DrarillionSlayer. If anybody could check it out and give me some pointers on how to get this working more efficiently please reach out! (Also if you download the project, controls are WASD and J to attack)

This is what you have collision groups and collision masks for.

1 Like

Okay thank you! I’ll take a look at it and let you know if I have any more questions :slight_smile:

1 Like

Okay I have managed to classify each game object as one of four groups: enemies, player, mapCollision, and weapon.
-enemies are masked to weapon and mapCollision
-player is mapped to enemies and mapCollision
-weapon is mapped to default
-mapCollision is mapped to default

How do I go about handling collisions with these groups now? Or to be more specific how to get messages from them in a code snippet like this:


Instead of “trigger_response” how would I handle the weapon colliding with an enemy hitbox?

The link he posted there’s a section called Detecting collision and another link to Collision messages. Good examples and the basics of responses you get from collisions.

Yeah I’ve been trying to follow that but unfortunately none of my collision or triggers are working now after changing the mask and group away from default :confused: im just not sure what I’m doing wrong

OK, you can follow a few steps:

  1. Make sure the groups and mask are working:
    if “collision_response” then print(“collisions working \o/”)
  2. Filter the collisions by groups:
    I wont give you the straight answer here (but is there on the docs as well) but try to print the message you get from the collision response. Use pprint() (yep, an extra ‘p’ to print a table)
2 Likes

I was able to get it working now! I just had some of the groups created incorrectly. This is my first game in Defold so it’s a lot of trial and error but, I have loading zones and basic combat working now! Thank you

4 Likes