CREATE YOUR WORLD
Interacting with Objects

Applying Vehicles to ZEPETO Characters

20min

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]



Setting Up the Animator

To change the pose of the ZEPETO character when riding a vehicle as described above, you need to modify the Animator and set it up under ZEPETOPlayers.
To change the pose of the ZEPETO character when riding a vehicle as described above, you need to modify the Animator and set it up under ZEPETOPlayers.




1) Create an Animator Controller by going to Project > Create > Animator Controller and rename it to VehicleZepetoAnimator.

Document image




2) In the Animator tab, create an Empty state by selecting Create State > Empty.

Document image




3) Rename it appropriately in the Inspector and assign animation clips to Motion.

Document image




  • 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.

Document image


👍 Tips

  • If the camera height needs to change depending on the size of the vehicle, you can preset the Camera LookOffset value in ZEPETOPlayers.



Example Code

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.
TypeScript




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.

Document image




👍 Tips

  • You can create various vehicles by simply changing the Prefab of the vehicle and the animation clips of the character.
Document image




Example of Size Change When Consuming Items

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.

Document image

Document image




3) Create a TypeScript by going to Project > Create > ZEPETO > TypeScript and rename it to ChangeObjectSize.

4) Write a sample script as shown below.

TypeScript




  • 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.

TypeScript




  • 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.

Document image




Interacting with Vehicles

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]



Setting Up

1) Set up the DockPoint object and UI prefab on your vehicle prefab in the same way as the interaction guide.

Slime Prefab with Dock Point Set Up
Slime Prefab with Dock Point Set Up




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.

Slime Prefab with Collider Set Up
Slime Prefab with Collider Set Up




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.

Completed UI Button Setup
Completed UI Button Setup




5) Create an empty object as a child of DockPoint by going to Hierarchy > Create Empty Object, and rename it to IconPos.

Document image




6) Set up PrefIconCanvas in the same way as the object interaction guide, and then make it into a prefab.

Document image




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.



Adding Boarding Animation to the Vehicle

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.

Document image




2) In the custom animator → Parameters → [ + ], add a Bool Condition and rename it to isRiding.

Document image




3) For the transition from Sitting to Idle state, click Conditions → [ + ] and add the isRiding Condition with the option set to false.

Document image




4) For the transition from Idle to Sitting state, click Conditions → [ + ] and add the isRiding Condition with the option set to true.

Document image




Script

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.

TypeScript




  • 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.

Document image




[▶︎(play)] Press the play button to try boarding the vehicle.

Resulting screen
Resulting screen




👍 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.