STEP 17: Uh oh! We have a problem. Our soccer player is moving up and down, not our soccer ball.

In a collision event, sprite refers to the object that hits, and hit_sprite refers to the object getting hit.

  • In our program sprite is our soccer player, and hit_sprite is our soccer ball.
  • On our indented line, change the name in front of.set_y_speed(5) from sprite to hit_sprite.
  • Click Run. Now our soccer ball should be moving up once it hits our player!

Not started reading
microbit = codesters.Microbit() microbit.show_string("hello") stage.set_background("soccerfield") sprite = codesters.Sprite("athlete2") sprite.move_down(150) def button_a(): sprite.move_left(50) microbit.event_button_a(button_a) def button_b(): sprite.move_right(50) microbit.event_button_b(button_b) ball = codesters.Sprite("soccerball") ball.set_x_speed(5) ball.set_y_speed(5) def collision(sprite, hit_sprite): sprite.set_y_speed(5) sprite.event_collision(collision)
Not started