Move until collision?

I’m new to CoSpaces and fairly new to coding in general. I teach 7th & 8th grade technology and they LOVE using CoSpaces. I am creating different scenes for practice. I have created this scene ( with a witch, a vampire, a GROUP of bats, and a cat. I want the witch to circle the vampire until the group of bats collides with her. I have tried every bit of coding I can think of and it still is not working. In this version of the scene she is just circling the vampire forever. When you click on the vampire, the bats attack the witch, but nothing I have tried works to make her stop or break out of the loop. Please, can someone help me?

Hi @Jasap,

That’s a fun practice space! Your code was only missing a way to check when the bats have collided with the witch. Below you can find a possible solution :slight_smile:.

Simply click the remix button to copy this space and see what code has changed to make the collision detection possible.

Here’s what changed

  • The Witch script makes use of a variable called hasCollided. This variable will be set to true when the largest bat (Bat3) collided with the witch. We’re setting up an event handler for this case.
  • While the variable hasCollided is false, we’ll repeat the turn block with a repeat until - block. This loop acts similar to a forever loop, but can be given a condition so it knows when to stop.

I also noticed that the Big Sakurai Bonsai item you used from Google Poly slows down the space a lot and replaced them with the other Bloodwood tree items. If you want to use them in this new version you can find all items you uploaded to the space in the Upload tab under the 3D models category.

Hope this helps!

Thank you SO much! I tried using a variable at one point, but I must have set it up incorrectly.

1 Like

The remix button is not yet available. Can you add please?

Hi @Roberto_Raspa,

Remixing of CoSpaces is available in the PRO plan - see CoSpaces Pricing for details.

Hope this helps! Let me know if you have any further questions about this.

Geoff @ TechLeap

1 Like

Perfect, thanks a lot.

1 Like