Back and forth from the edge to the middle of the screen

Hi! I want to move a ball (ball 2)from the left edge to the middle of the screen. When the ball reaches the middle of the screen I want it to move back to the left edge.
However the ball (Ball2) does not change the heading when it reaches the middle of the screen, it reaches the right edge and it stops there. The blocks:


I've also tried it this way:
image
Any ideas where the problem is? Thank you

Try using "greater than" instead of equals to. As the Ball moves across the screen to the right, it may never equal the centre value (it could skip passed it)

Thank you for your answer. I've tried it and it does not work either

You most likely have to continually check/monitor the Ball2 coordinates (just the x value) using a Clock event handler.

Creating Animated Apps might help you resolve this.

Also check out https://groups.google.com/g/mitappinventortest/c/oIG_MdES7aU/m/GD9wS37MZP8J

If you set the Clock TimeInterval to 250 ms, you can do this

ballLimits :slight_smile:

2 Likes

Stick a ball in the centre of the screen and make its background colour the same as the canvas.

When Ball2 collides with the above ball reverse its heading.

1 Like

It works!!! Good idea!!!! Many thanks!!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.