Thursday, 2 April, 2020 UTC


Summary

7 Steps To Setup A Basic VR Multiplayer Ball Toss Using Normcore

Here’s how you can setup a functional multiplayer ball toss in less than 10 minutes. I saw a lot of people who had never worked with Multiplayer setup asking how to setup this scenario. It also took me a while to figure it out despite how simple Normcore makes it compared to other Multiplayer services. To save ya’ll the effort, here is my 7 step solution:
Setting Up The VR Player-
*This tutorial assumes you’ve already setup your OVRPlayerController through Oculus Integration
  1. Download Normcore and Import it into your Unity project here (Sign-Up required — It’s Worth It!)
  2. Once imported, setup VR player — Find “Realtime + VR Player” and drag it into Hierarchy (Normal>Examples>VR Player)
Add “Realtime + VR Player”
3. Create “App Key” here. Enter that App Key into “App Key” field on Realtime + VR Player”
Enter App Key
4. Drag “OVRPlayerController” onto the “Root” field, “CenterEyeAnchor” onto “Head”, “LeftHandAnchor” onto “Left Hand”, “RightHandAnchor” onto “Right Hand”
Add OVRPlayer to Avatar Manager Fields

Trending AR VR Articles:

1. Ready Player One : How Close Are We?
2. Augmented Reality — with React-Native
3. Five Augmented Reality Uses That Solve Real-Life Problems
4. Virtual Reality Headsets: What are the Options? Which is Right For You?
Setting Up The Throwable Object-
5. Create Prefab of Throwable Object — named “NormcoreGrabbable” (Add Rigidbody, Collider, OVRGrabbable script [assign grab point], RealTimeView script [uncheck ‘Owned by Creating Client’], RealTime Transform script, custom script to detect grab and ownership request (example GrabRequest script below)
Create Cube & Add Components
6. Place this prefab in the “Resources” folder (then delete from hierarchy)
Drag Cube to Resources (prefab)
7. Create InstantiateGrabbableObject script (example below), drag it onto “RealTime + VR Player” object currently in hierarchy.
Add InstantiateGrabbableObject

BOOM! You’re Done. Make a VR build and send it to a friend to test that shit out (because who wants to test out multiplayer features alone).

GrabRequest script-
using UnityEngine;
using Normal.Realtime;
public class GrabRequest : MonoBehaviour
{
private RealtimeView _realtimeView;
private RealtimeTransform _realtimeTransform;
private void Awake()
{
_realtimeView = GetComponent<RealtimeView>();
_realtimeTransform = GetComponent<RealtimeTransform>();
}
private void Update(){
if (gameObject.GetComponent<OVRGrabbable>().isGrabbed)
{
_realtimeTransform.RequestOwnership();
}
}
}
IntiantiateGrabbableObject script-
using UnityEngine;
using Normal.Realtime;
public class InstantiateGrabbableObject : MonoBehaviour
{
private Realtime _realtime;
private void Awake()
{
// Get the Realtime component on this game object
_realtime = GetComponent<Realtime>();
// Notify us when Realtime successfully connects to the room
_realtime.didConnectToRoom += DidConnectToRoom;
}
private void DidConnectToRoom(Realtime realtime)
{
//Instantiate the CubePlayer for this client once we've successfully connected to the room
Realtime.Instantiate("NormcoreGrabbable", // Prefab name
position: Vector3.up, // Start 1 meter in the air
rotation: Quaternion.identity, // No rotation
ownedByClient: false, // Make sure the RealtimeView on this prefab is NOT owned by this client
preventOwnershipTakeover: false, // DO NOT prevent other clients from calling RequestOwnership() on the root RealtimeView.
useInstance: realtime); // Use the instance of Realtime that fired the didConnectToRoom event.
}
}
**If you read this far, checkout our Asynchronous Multiplayer VR Game here to see how this works when done.
  • **not a Normcore employee, so all errors in above instruction are liable due to poor instruction by the writer, no fault of Normcore.

Don’t forget to give us your 👏 !

https://medium.com/media/1e1f2ee7654748bb938735cbca6f0fd3/href
How-To: Setup A Basic VR Multiplayer Ball Toss Using Normcore was originally published in AR/VR Journey: Augmented & Virtual Reality Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.