Utilizing the Gyro Sensor
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.
๐ Gyroscope https://docs.unity3d.com/ScriptReference/Gyroscope.html๏ปฟ
๏ปฟ
1) Add Hierarchy > [+] > 3D Object > Sphere object to the Scene.
2) Change the object's name to Ball and add a Rigidbody component.
๏ปฟ
1) Add TypeScript and rename the script to RollingBall. Write a sample script as shown below.
๏ปฟ
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.
๐ Gyroscope.gravity https://docs.unity3d.com/ScriptReference/Gyroscope-gravity.html๏ปฟ
๏ปฟ
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.
๏ปฟ
1) Run the example world with QR mobile test.
2) The Ball object moves according to the device tilt.
๏ปฟ
โ๏ธ Caution Please note that Input.gyro only works in mobile environments.
๏ปฟ
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.
๏ปฟ
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.
๏ปฟ
3) When running the example world as a QR mobile test, the ZEPETO character moves according to the tilt of the device.
๏ปฟ
๐ 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!
๏ปฟ