Push the pendulum
Updated
A pendulum hangs from a fixed pivot on a Spherical Joint, a ball and socket; each press of P gives the bob a sideways impulse and it swings, free to turn in any direction about the pivot.
Click the view, then press P to push the bob; press it again mid-swing to add to the swing. Drag to orbit the camera, scroll to zoom.
Push the pendulum
#pragma lifecycle(startup, update)
let bob;
function startup() { bob = findEntity('Bob').getComponent(PhysicsRigidBodyComponent);}
function update() { if (Input.keyboard.isKeyReleased(Key.P)) { bob.applyImpulse({ x: 2, y: 0, z: 0 }); }}How it works
Section titled “How it works”The script is explained step by step in Push the pendulum.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
PushPendulum.xrproj