Applying Vehicles to ZEPETO Characters
By applying the guide on attaching objects to ZEPETO characters, you can implement riding vehicles like cars, airplanes, pets, etc., as if the character is riding them.
📘 Please refer to the following guide [Attaching objects to ZEPETO characters]
1) Create an Animator Controller by going to Project > Create > Animator Controller and rename it to VehicleZepetoAnimator.
2) In the Animator tab, create an Empty state by selecting Create State > Empty.
3) Rename it appropriately in the Inspector and assign animation clips to Motion.
- To use your desired animation clip files, refer to the Custom Animation guide.
📘 Please refer to the following guide [Apply custom animation]
4) Drag and drop VehicleZepetoAnimator onto ZEPETOPlayers to set it up.
👍 Tips
- If the camera height needs to change depending on the size of the vehicle, you can preset the Camera LookOffset value in ZEPETOPlayers.
1) Create a TypeScript by going to Project > Create > ZEPETO > TypeScript and rename it to RideVehicle.
2) Write a sample script as shown below.
- Note that the Vehicle Transform values in this example should be adjusted to match the Vehicle Prefab when actually applying it.
3) After completing script writing, add the script to the GameObject in the Scene.
4) In the Inspector, assign the vehicle's prefab resources and the Body Bone to be attached.
5) Click the Play button, and you'll see the ZEPETO character riding on the vehicle.
👍 Tips
- You can create various vehicles by simply changing the Prefab of the vehicle and the animation clips of the character.
Here is a fun application example: implementing content where the character's size changes when consuming items while riding a vehicle.
1) In this example, we prepared two types of prefabs and set the Tag of items that increase in size when consumed as "Increase" and items that decrease in size as "Decrease."
2) Add Colliders to each item and make sure to check IsTrigger.
3) Create a TypeScript by going to Project > Create > ZEPETO > TypeScript and rename it to ChangeObjectSize.
4) Write a sample script as shown below.
- The key part of the code is modifying the localScale to change the size of the ZEPETO character when it touches each item.
- Feel free to adjust the numbers for size change
- but make sure to handle exceptions to prevent the scale from becoming smaller than (1,1,1).
5) This script should be added to the ZEPETO character created at runtime. Therefore, modify the RideVehicle script that attaches the vehicle as follows.
- Code to add the ChangeObjectSize script at runtime has been added.
6) Click the Play button, and you'll see the character's size changing each time it consumes an item.
By applying the interaction guide, it is possible to implement boarding a vehicle at a desired location after interacting with it.
📘 Please refer to the following guide. [Interacting with an object]
1) Set up the DockPoint object and UI prefab on your vehicle prefab in the same way as the interaction guide.
2) In the Unity editor, make sure the transform gizmo toggle button at the top is set to Local, and rotate it so that the Z-axis (blue arrow) points outward from the object.
3) Add a Collider component and check the isTrigger option.
4) Adjust the size of the Collider to the range within which the player can interact with the object.
5) Create an empty object as a child of DockPoint by going to Hierarchy > Create Empty Object, and rename it to IconPos.
6) Set up PrefIconCanvas in the same way as the object interaction guide, and then make it into a prefab.
7) Additional Step: Create a Dismount Button
- Create a button as a child of the vehicle object by going to Hierarchy > UI > Button, and rename it to Get Off Button.
When a character gets on or off a vehicle, they need a natural animator setup to match.
The guide below will help you through the animator settings required for getting on or off.
Refer to the guide on applying custom animations to add a sitting animation state to your custom animator.
📘 Please refer to the following guide. [Applying Custom Animation]
1) Right-click on the added animation state, click Make Transition to create a transition from Idle to Sitting and back from Sitting to Idle. Select the created transition and uncheck the Has Exit Time option.
2) In the custom animator → Parameters → [ + ], add a Bool Condition and rename it to isRiding.
3) For the transition from Sitting to Idle state, click Conditions → [ + ] and add the isRiding Condition with the option set to false.
4) For the transition from Idle to Sitting state, click Conditions → [ + ] and add the isRiding Condition with the option set to true.
Write the InteractionIcon.ts script, same as the one in the interaction guide, which displays the interaction UI when entering the trigger area of the vehicle prefab.
Add the written InteractionIcon ZEPETOScript to the DockPoint object, and assign Pref Icon Canvas and Icon Position in the inspector.
Refer to the RideVehicleExample below for sample code on how to board the vehicle after interacting with the UI.
- The flow of the script is as follows:
- Start()
- When the icon is clicked, this._interactionIcon is deactivated, and the DoInteraction() function is called.
- DoInteraction()
- Set the animator's transition values to play the Sitting animation.
- Start the Snap Bone() coroutine to attach the ZEPETO character's bodyBone to the targetTransform.
- Use the function this._localCharacter.StateMachine.constraintStateAnimation = true; to disable the current animator's transition, locking in the currently playing animation.
- The Parent of the vehicle object changes to the ZEPETO character.
- The Get Off button in the top right is activated.
- StopInteraction()
- Set the animator's transition values to play the Idle animation.
- Re-enable the animator transition so that the appropriate animation plays according to the situation.
- Set the Parent of the vehicle object to null.
- Deactivate the Get Off button.
- this.getOffBtn.onClick
- The StopInteraction() function is called.
- this._interactionIcon is activated.
Add the written RideVehicleExample ZEPETOScript to DockPoint, and assign the Get Off Button and vehicle prefab in the inspector.
[▶︎(play)] Press the play button to try boarding the vehicle.
👍 Tips
- The above sample is an example of content not considered for multiplayer synchronization.
- To implement multiplayer synchronization, you need to synchronize information such as which vehicle each player is riding, and the size and location of the vehicle, as Room State.