Getting object to move randomly

I was wondering if you could help these students out. On Scene 2 and Scene 3 of CoSpaces Edu :: Cohort 9 Project they want the arrows to move up the wall. However, each time you play, they want a different arrow to move each time. For example, the red arrow will move first one game, but then the next time you play a different arrow will move first. Once you press the corresponding arrow key on the keyboard, a different, random arrow will move up the wall. Once you press that corresponding key, the third will move up the wall. Any ideas? Thanks!

1 Like

Hi @Kelly_Nickell,

Your students got a very interesting challenge! The behavior you describe is similar to rhythm games. To randomize the arrow movement and to have their movement match to keyboard inputs involves some complex logic. Below is an example of how such game could be made in CoBlocks.

Key behaviors

  • Give each arrows unique names and place them into a CoBlocks item list
  • Randomize which arrow to move up first by selecting from a random item in the list and move it up via transition block
  • Set up collision events that define if the corresponding arrow key is ok to press

This coding challenge covers the use of lists, variables and event handlers. I highly recommend checking out our CoBlocks tutorials to learn how to use them :slight_smile:

Here is also a remixable space to help seeing the CoBlocks code work in context.

The space has two example scenes. The first scene shows the behavior you requested and the second one shows how the CoBlocks code can be modified to make the rhythm game become endless.

I hope this helps guiding your students to the right direction!