Skip to Content

Collison Detection Between Sprites

« How do I...?
3 replies [Last post]
Laura Webber
Member

I've been using Scratch for 3 years with my Intro and AP comp sci classes. My students and I have noticed really inconsistent collision detection between sprites.

 

For instance, if a program a dragon sprite to bounce off a prince sprite, the dragon doesn't bounce off the prince's edge. Sometimes it appears like the dragon bounces off the prince's centerpoint, or sometimes not at all.

Does anyone know the inner workings of Scratch's collision detection?

A lot of the time, we've just switched to detect colors as a way to get around this.

Replies
Laura Webber
Member

Thanks for the suggestions. I will try multiple contact points.

It came up again today with a student who put a shooting element into her game.

When the bullet hits the dragon, nothing happens. Only when the bullet the exact center of the dragon does it increment the score. This is a little too sensitive for her game.

We tried to change it to sensing the color of the dragon and the results were even worse.

I'll see what we can accomplish today. Thanks so much.

Ai Boon Tan
Member

Hi. I don't know the inner workings of collision detection in Scratch. Just wish to share how we solved a similar problem.

In a project (see link below) I was creating, my sprite OOgy refused to stay on the yellow path. My son Timothy,  taught me a way to get round thproblem. He asked me to design the sprite with special contact points. If you take a look at my sprite OOgy in the project  "The adventures of OOgy" at http://scratch.mit.edu/projects/aitan/1297995, I had initially designed it without the hat and shoes. I had many problems because OOgy could easily get into the blue parts and refused to stay on the yellow path. So Timothy added in the hat and shoes as contact points and that solved the problem. In this project, we used colours for sensing.

I believe that  if you design your sprites with specific contact points,  you will be able to solve your problem.

However, if the moves are too many, for example "move 10 steps" instead of "move 1 step", OOgy is once again able to get off the yellow path.  This is exactly the case as described by Karen above.

Ai Boon

Karen Randall
Member

There's a couple basic things to check for, just in case your kids haven't found them:

  • The sprite's center of rotation (in the costume editor) in the center?
  • When the sprite are colliding, how many steps they take in a "move" block.  If the moves are big, they can pass over the sprite before getting to the command that checks for touching.

Karen R.