Collision not working in game

My students are creating their games in Game Lab; however, I have students creating a maze game, but they cannot keep their sprites from going through the walls. They have tried all of the collision commands, but they are not working for them. Does anyone have any suggestions, so I can better assist them?

For us to help you best, it would be very helpful for you to answer the following and we can take a look and help you out …

To get help as quickly as possible, here are a few things that are great to include in your post

  1. Link to your project: click the “Share” button at the top of the page and paste the link it produces into your post.
  2. Are there any particular steps that cause the error?
  3. What did you expect the program to do?
  4. What did it do instead?
1 Like

Hi @thompam1,

In general it sounds like there needs to be a line that says “if [sprite] is touching [wall], then [go back to start / lose a point / whatever else you want them to do]”. However, like @mwood said, we can help a lot more if we have a link to their code so we can see what they’re thinking. Often it’s just a line or two that needs a minor tweak!

–Michael K.

Here is one of my student’s game that has that problem…

@thompam1,

Thanks for sharing the code. In the example you shared, I don’t see anywhere where your student has tried to detect collision with the wall and any of the characters. I do see collision detection between the elf and the snowman and between several of the sprites and the present, and I see those collisions all working.

If they tried detecting collisions with the wall, they must have removed that code…

Let us know…

thanks,

Mike

Yes, they deleted it. They tried all of the collision commands, and none of them worked.

Without spending some time trying to recreate it, I’m wondering if it’s because the walls are all one giant sprite and even though there are some transparent parts of the sprite, you can’t collide with a single wall because anytime you’re inside the rectangular confines of that sprite, you are colliding with the entire sprite.

One solution would be to create multiple sprites and draw the walls with a number of sprites. Of course this would take more time, but I don’t think having one sprite as the entire wall system will work as it is currently designed.

Anyone else have any thoughts on it?

Mike

As another quick followup, if you follow this thread on the forum, there is an example of how to create a group that contains multiple sprites. You could create a group called “walls” and add all of the individual walls to the group, and then you could set the collision rules with the “walls” group so you didn’t have to check collision with each wall individually. This seems like the most efficient way to handle it, although I am sure there are other ways.

Hope this helps.

Mike

I have a solution. I repurposed a super old game. Here it is:
https://studio.code.org/projects/gamelab/FCcyZVTK5XzEGMHrgR5i5JlxSkvJCvgo0S6vJjKFDA8/view
Drag boxes to create rectangles, press g to export the sprite-group. Press z if you make a mistake. I don’t really have time to do it myself.