Yaw VR Motion Simulator Unity package v.0.5
Git repository: https://bitbucket.org/yawvr/unity-sdk/src/master/
Description about yaw device communication
Description
Yaw VR package helps you managing and controlling Yaw VR Motion Simulator from your unity project.
Installation
Import YawVR package into your unity project (include everything)
How it works
The YawController sends the YawTracker object’s orientation to the connected device.
To control the simulator, you just have to animate/control the YawTracker object’s orientation, and it’ll be sent to the physical device.
Usage
- Find YawController & YawUI prefabs in YawVR/Prefabs folder.
- Drag YawController prefab into your scene (YawController.cs script calls DontDestroyOnLoad() on YawController gameObject, so it won’t be destroyed when you have multiple scenes in your game)
- Click on YawController gameObject to be able to observe it on the Inspector Panel
- Locate your gameObject whose motion the simulator should follow and attach a sample script to it (YawVR/Sample/ControSamples)
- Set game name on YawController script
- Drag YawUI prefab to your scene / menu scene (optional)
- YawUI gameObject is our example implementation showing how to use YawController’s functionality.
- Feel free to modify or integrate it in your existing menu. If you chose not to use it, you have to setup YawController gameObject on your own.
- Run your project (To be able to establish communication between your game and the simulator, you have to be connected to the same network)
If you have difficulties in communication between your game and the simulator:
- Check if your network / router allows sending TCP and UDP messages to the chosen ports.
- Set your firewall settings accordingly
Detailed usage of YawController gameObject
YawController gameObject is responsible for discovering available simulators, connecting to a device, sending commands.
In order to call YawController gameObject to set up and control your simulator, you have to use its singleton instance:
e.g.:
YawController.Instance().<...>());
All simulator related classes are found under YawVR namespace, so you either use full class paths,
(e.g. YawVR.YawController.<…>() ; )
or you can omit it with the using directive:
using namespace YawVR;
…
YawController.<…>() ;
YawController uses callbacks and delegate functions to provide feedback about asynchronous events (eg. connection success/failure)
To use acceleration as the motion source of simulator rotation, your reference gameObject must have a Rigidbody component.
- Call YawController.Instance().DiscoverDevices() method
- YawController sends a broadcast UDP message and then when a device responds to this discovery broadcast, YawController calls YawControllerDelegate.DidFoundDevice(YawDevice device) delegate function
- To have an up to date list of currently available devices, call this function repeatedly.
- You can create a YawDevice object without using device discovery, just create a new instance of YawDevice class with your known IP address and ports.
- Call YawController.Instance().ConnectToDevice(myDevice, onConnectionSuccess, onConnectionError)
- You can provide a callback Action which will be called when your game successfully connected to the device, and an Action<string> callback which is called on an unsuccessful connection to the tcp server of the device, or when the device is reserved and refuses connection, or if device is not responding within reasonable time.
- When calling this method, YawController attempts to connect to the device’s TCP server, and in case of success, it sends a CHECK_IN tcp command to the device.
- YawController’s State becomes ControlerState.Connecting, and will be waiting for the response of the target device, with a timeout.
- When the simulator accepts connection and reservetion from the game, State becomes ControllerState.Connected.
- Starting connected device:
(e.g. you call this method when you start a new game scene)
- Call YawController.Instance().StartDevice(onSuccess, OnError)
- It sends a START command to the connected simulator, and State becomes ControllerState.Starting
- After a successful start, state becomes ControllerState.Started, and YawController starts to send rotation values to the simulator
- Stopping connected device:
(e.g. you call this method when user opens menu during the game)
- Call YawController.Instance().StopDevice(onSuccess, OnError)
- It sends a STOP command to the connected simulator, State becomes ControllerState.Stopping and YawController stops sending rotation values to the simulator
- After a successful stop, state becomes ControllerState.Connected
- Disconnecting from connected device:
(e.g. you call this method when user exits from the game)
- Call YawController.Instance().DisconnectFromDevice(onSuccess, OnError)
- It sends an EXIT command to the connected simulator, and State becomes ControllerState.Disconnecting
- After a successful disconnection, and even if an error happens during disconnection, state becomes ControllerState.Initial
- ControllerState State { get; } - The current state of the controller, which represents the state of the simulator. When State changes, YawControllerDelegate.ControllerStateChanged(ControllerState state) delegate function gets called
- YawDevice Device { get; } -The currently used Yaw VR Motion Simulator - can be null if no device is connected
- GameObject ReferenceGameObject { get; } - The gameObject whose motion the simulator should follow
- YawControllerDelegate ControllerDelegate { get; set; } - The delegate of YawController - on which YawController calls YawControllerDelegate methods
- bool ShouldRememberDevice { get; } - If true, YawController attempts to connect to the previously used device on game start
- ReferenceMotionType ReferenceMotion { get; } - Can be Rotation/Acceleration/Mixed - the type of motion the simulator’s movement should follow
- Vector3 RotationMultiplier { get; } - Multiplies the rotation source of sent rotation values. Default value is (1,1,1)
- Vector2 AccelerationMultiplier { get; } - Multiplies the acceleration source of sent rotation values. Default value is (1,1). Only affects the simulator’s pitch and roll movement
- float LateralForceMultiplier { get; } - Default value is 1, multiplies the lateral force source of sent rotation values. Only affects the simulator’s roll movement
- Vector3 ReferenceRotation { get; } - The observed euler angles of the reference gameObject
- Vector2 ReferenceVelocity { get; } - The calculated velocity of the reference gameObject in its own space, sampled with MotionSampleSize
- Vector2 ReferenceAcceleration { get; } - The calculated acceleration of the reference gameObject in its own space, sampled with MotionSampleSize
- float ReferenceTurnAngle { get; } - The calculated turn angle of the reference gameObject in degrees/sec, calculated from velocity vector changes, used to calculate lateral forces.
- float ReferenceLateralForce { get; } - The calculated lateral force affecting the reference gameObject in its own space, calculated from ReferenceTurnAngle. Sampled with MotionSampleSize.
- TiltLimits TiltLimits { get; } - The current angular limits of tilt movement
- float? YawLimit { get; } - The current angular limits of yaw movement
- int MotionSampleSize { get; } - The sample size used for sampling motion related data
- void SetGameName(string gameName) - Sets the name of your game which is used by the simulator to identify your game-related configuration
- Setters related to motion data processing
- void SetRotationMultiplier(float yaw, float pitch, float roll) - Sets the multipliers which modify the rotation component of rotation values sent to the simulator.