Collision Mask Help

I’m new to GDevelop and I’ve run into something I don’t understand with collision detection in HTML5 games. I created three sprite objects and an event. If the first object (Simon Belmont) is in collision with the second object (green box), a third object (skeleton) is spawned. But when I preview it in a browser, the collision detection seems to occur BEFORE Simon Belmont and the green box actually collide. I’ve edited the hitboxes to be much smaller than the sprites and yet it doesn’t seem to help. If anyone can tell me what I’m doing wrong or if I’ve misunderstood something it would be much appreciated! Screen shots of the edited hitboxes, code, and browser output are provided below. Thanks for taking the time to read this!




Hi,

HTML5 games don’t support sprites custom collisions masks.
A workaround is to use smaller hidden object that will represent the collision mask of the objects.

Ah?! That’s strange because I painstakingly edited the masks for my player and my rock so that the rock wouldn’t move unless it looked like the bunny’s hands were on it and it works.

Here I had to unmask his foot otherwise the rock followed him if he turned round.

FlamingBagOfJoy I think you should be using the Sprite collision (pixel perfect) condition instead of the Object collision condition. But then again I’m no expert so I may be wrong.

Thanks victor and annemb for the replies! I’ll experiment with both pixel perfect detection and creating objects to act as hitboxes and see what feels best. Many thanks again for the prompt reponse and useful advice! :slight_smile:

I’m not really sure I understood, why you need sprite collision in this case.

The example so far look like you are searching a 2d solution for a 1d task.
If the distance between your sprite (or a specified point on it) and the rock (or a specified point on it) is zero (or below a specified value) and player moves toward rock (and rock is still movable to that direction) → player pushes rock.

(Pixel perfect) Sprite collision might check hundreds of pixels for collision on every loop of your project.
Calculating just the distance should be a little bit faster - less calculation => better performance.

Do you have an example?
The beginners’ platformer tutos use sprite collision for interactions with enemies and collectibles so I assumed this was the best way to do this.

Here is the example.
I hope I can upload the file, too. Having an avatar picture would be nice, if I only understood where I have to upload what.
I don’t understand why I can upload large pictures and maybe even files in forum, but I have to upload my avatar somewhere else.

Back to the example.
Something regarding the animation isn’t working and I’m sure it can be improved, as I’m just a beginner.

I made the “rock” useable as a platform.
To be honest - I was surprised, that my way of “pushing” also created a slowdown of the player - didn’t expect that :astonished: and I don’t understand :confused: , but I like it :mrgreen:.


PushExample.7z (61.5 KB)

Thanks videotas, I tried this but it doesn’t suit my needs. Using the value of 73 for the distance makes the rock move while there is a considerable distance between it and the player and reducing this value produces a horrible flickering. Another issue is that if I try pushing the rock to the left it works for a while but then seems to get stuck. I can see that this method can be useful for some animations but here I want it to look like the player is actually pushing the rock and not applying some sort of force field on it. It’s a pity because I had tried to slow down the player without succeeding. I’ll perhaps try the workaround with a smaller hidden object although I’m not convinced that the extra code needed to keep them moving along with their “hosts” would be more efficient in the long run.

It would be nice to know which solution FlamingBagOfJoy has found to be better for what he’s doing.

I’ve been experimenting with the two methods a bit. For some reason changing the collision type to pixel perfect doesn’t seem to make much difference when I run it in the browser. The collision still seems to register before the two sprites come into contact. I don’t know if this is something to do with html5 vs. native platform, or (far more likely) that I’ve misunderstood something. As for the small hidden object method I found it worked quite well for my needs. To get the sprite and hidden object to line up perfectly with each other I had to change their origin points to the same settings as their centre points and then it worked like a dream.

Here’s the code I used for testing each method.

Pixel Perfect Collision

Small Hidden Object

Thanks again to everyone for responding to my query! If there’s anything else I should know or that I’ve misunderstood please feel free to set me straight! Thanks again! :smiley:

Sorry, pixel-perfect collision doesn’t work in html5 platform, but I’m unsure why.

That’s good to know, thanks for the info! Now that I understand that Collision Masks and Pixel Perfect Collisions aren’t available in html5, I’ll build everything to use hidden objects. Thanks once more to everyone for explaining all this to me.