CREATE YOUR WORLD
User Interface

Utilizing the Gyro Sensor

8min

When creating ZEPETO World, you can use the Gyro Sensor to implement various world play ideas depending on the tilt of the device. This guide will show you how to utilize Input.gyro within ZEPETOScript.

๏ปฟ

Setting up object

1) Add Hierarchy > [+] > 3D Object > Sphere object to the Scene.

2) Change the object's name to Ball and add a Rigidbody component.

Document image
๏ปฟ

๏ปฟ

Writing a script

1) Add TypeScript and rename the script to RollingBall. Write a sample script as shown below.

TypeScript
๏ปฟ

๏ปฟ

Script Description

  • Gets the Rigidbody component attached to the Ball object.
  • Round the Input.gyro.gravity.x and Input.gyro.gravity.z values โ€‹โ€‹to get gyroValueX, gyroValueZ values.
  • Give speed to the Ball object by substituting the gyroValueX and gyroValueZ values โ€‹โ€‹multiplied by velocityMultiplier into velocity.
  • The Input.gyro.gravity value is displayed on the screen through Text UI.

๏ปฟ

2) Add the RollingBall ZEPETOScript you wrote to the Ball object. In the Hierarchy window, connect the Text UI to the Property displayed in the ZEPETOScript Inspector window by dragging and dropping.

Document image
๏ปฟ

๏ปฟ

Testing on mobile

1) Run the example world with QR mobile test.

2) The Ball object moves according to the device tilt.

Document image
๏ปฟ

๏ปฟ

โ—๏ธ Caution Please note that Input.gyro only works in mobile environments.

๏ปฟ

Applying the example

You can move the ZEPETO character within ZEPETO World by applying Input.gyro.

1) Add TypeScript and rename the script to GyroMovement. Write a sample script as shown below.

TypeScript
๏ปฟ

๏ปฟ

Script Description

  • When a local player is added to the Scene, receive a ZEPETO character instance.
  • Round the Input.gyro.gravity.x value to get the gyroValue value.
  • Move the ZEPETO character in the Z-axis direction by assigning direction as a parameter to the Move() function.

2) Add a GameObject to the Scene and rename it GyroGravity. Add the GyroMovement ZEPETOScript you created.

Document image
๏ปฟ

๏ปฟ

3) When running the example world as a QR mobile test, the ZEPETO character moves according to the tilt of the device.

Document image
๏ปฟ

๏ปฟ

๐Ÿ‘ Tips

  • In addition to Input.gyro.gravity used in this example, you can use various Input.gyro functions.
  • You can apply this to various ideas. Try releasing a fun world on ZEPETO!

๏ปฟ