VRChat - Sushi Belt

From ScottWiki
Jump to navigation Jump to search

How to create a moving sushi belt in your VRChat World (回転すし)

Concept

There are many ways you can do this in VRchat / Unity, and I shall explain in detail how I did this as in the VR chat world (Higashimon Street)

https://vrchat.com/home/launch?worldId=wrld_605dbf6f-48e0-4c86-a259-0ff9b39d1fdf

If you wish to see the working sushi belt, head over this world and check out the 2nd shop on the left.


The basic idea of how to create a sushi belt is we are going to use 2 colliders, (one for each side of the sushi belt) If an object is placed inside this collider it will move to slowly towards one end of the collider / belt. If the object reaches the end of the collider / belt then it is moved to the opposite belt where it travels in the other direction until it reaches the end of this belt and it is moved back to the first belt. Any object that is paced on the belt will effectively rotate like on a sushi belt.

http://solaris.scottworld.net/downloads/sushi.png


Setup / PreRequisites

Create your basic VRChat World (add your spawn point)
Head over to https://github.com/MerlinVR/UdonSharp and install the latest UDON# package from merlin. (this is a really nice package lets us use simple c# code rather than the node interface) I use a combination of both in my worlds. Using the udon node interface for "simple" tasks. I use the Udon # method for more complicated tiggers / events.
Import SDK3
Set up standard VRChat world requirements.
Import Merlin Udon#

Create a collider, you want for the area of the sushi belt. (set it as a trigger) On the collider

Add a Udon Behaviour Script to the collider
Add the Sushi Move Udon# script to the Udon Behaviour
Create your Start / End / Teleport Game objects.
Assign those Game objects to the relevant Points in the Inspector.
Set the speed.

Build and test...


I have created a package here, which contains all the packages with an nice simple example. (this contains everything you need .. SDK / Script / Udon# and sample scene)

http://solaris.scottworld.net/downloads/sushibelt.zip



using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class SushiMove : UdonSharpBehaviour
{
    public GameObject track;            
    public Transform StartPoint;              <--- Defines and Exposes the Variable StartPoint (this is the start of the flow direction of the sushi belt)
    public Transform Endpoint;                <--- Defines and Exposes the Variable EndPoint (this is the End of the flow direction of the sushi belt the object will migrate to this point)
    public Transform TelePoint;               <--- Defines and Exposes the Variable TelePoint (When the object reaches the EndPoint it will TELEPORT to this point)
    public float Speed;                       <--- Speed of the belt (set about 0.1 for a sensible speed)
    private void OnTriggerStay(Collider other)
    {
        if (other == null) return;                <--- If a player puts their hand / body in the collider then DO NOTHING to the players hand etc)
        other.transform.position = Vector3.MoveTowards(other.transform.position,Endpoint.position,Speed * Time.deltaTime);    <--- Moves the object in the collider towards to EndPoint.
        if (other.transform.position == Endpoint.position)           <---- If the object reaches the EndPoint
        {
            other.transform.position = TelePoint.position;               <----- Teleport it to the TelePort point (this should be places inside the Next / return sushi belt colider)
        }
    }

    
}