How to make a Pendulum Obstacle

Last updated: February 24, 2025

Make sure to have claimed a plot, be in 'Create' mode, and press the 'Build' button on the left side of the screen until you see a toolbar appear on the right side of the screen.

Ever wanted to make an obby that swings side to side, knocking your players away? Then this code is for you!

  1. Let's make a pendulum model using a Ball and a cylinder. We want to go ahead an select these two parts, and press the merge button from the right toolbar to make them into one object, so we can apply code to it.

Click on the button in the red box on the right toolbar, then hit MERGE 2. Now let's open up Code Builder for your now-merged object by clicking the </> button on the right toolbar, and pressing the 'Code Builder' button. Name your script and object.

  1. Now go to 'Events' on the left side, and grab the At start block to play the swings as soon as the game plays. Then go to 'Control' and grab the do forever block (which automatically comes with an 'end' block), and place it below At start.

*Always save your code whenever you close Code Builder!
  1. Still in 'Control', grab a wait -- seconds block and place it inside do forever and end. Then, go to 'Motion' on the left side and grab tween rotation to x : 0 y : 0 z : 0 in -- seconds. This block will animate and control the swing of your object. Place it in between do forever and end, above wait -- seconds.

  2. Since we're rotating to certain coordinates, we want to get the correct rotation coordinates. So go to your plot and check the rotation axis of your pendulum by selecting your pendulum and rotating it to the amount you want for it to be at its full swing.

Unfortunately, editing the pivot (rotation point) of objects is not yet possible, so objects will always rotate from its center point. So make sure your cylinder is long enough. | ot, be in 'Create' mode, and press the 'Build' button on the left side of the screen until you see a toolbar appear on the right side of the screen.

The numbers in the red box represent the x, y, and z coordinates respectively

  1. Now let's go back to Code Builder and input these coordinates in our tween rotation block. I want them to swing quite fast, so let's set the duration within 2 seconds. We'll also set wait -- seconds by slightly more than 2 seconds. (the wait -- seconds provides a delay before running the next code. We want to ensure our pendulum reaches its maximum swing but also for the delay to not be too long, so set it to just above 2 seconds.)

  1. Now we want the pendulum to swing to the opposite direction. So duplicate your tween rotation block and wait -- seconds block and place it just below the original two, still inside do forever and end. The pendulum was rotating on the x axis, so we want to change the second tween rotation 's x value to -60 so it goes to the opposite direction.

  1. Don't forget to save your code, and when you press 'play', you should see your pendulum swinging side to side!
Bonus stage : Have multiple pendulums that swing in opposite directions
  1. Duplicate your first pendulum, then open the Code Builder of your duplicated pendulum. Click the unlink button.

  1. Then inverse the values in your tween rotation blocks. So in this case your first one would be x : -60, while your next block will be x : 60.
  2. Save your code and see your pendulums swinging in opposite directions when you press play!

Was this article helpful?

Thanks for your feedback!