Integrating Unity Physics with Vortex Studio
The purpose of this feature is to allow the use of Unity’s physics engine to procedurally produce physically based animation which can increase the immersivity and functionality of your content.
This feature allows some Unity GameObjects with rigid body components to react to Vortex mechanisms, and, vice versa, allows Vortex mechanisms to react to some Unity rigid bodies.
When using this feature;
one can specify which Vortex objects are to be respected by Unity, physics allowing for Vortex-controlled mechanisms to interact with Unity objects with no in-Vortex representation and no affect on the motion of the Vortex controlled mechanism (Vortex->Unity physics transfer). Effectively, this creates an infinite mass, or kinematic, body in Unity which is animated by Vortex.
simultaneously, Unity GameObjects with rigid body components can be streamed into Vortex, and so provide collision geometries for Vortex objects to collide with, but are not affected by Vortex dynamcs in turn (Unity->Vortex physics transfer). Effectively, this creates an infinite mass, or kinematic, part in Vortex which is animated by Unity.
Vortex->Unity Physics Transfer
To represent a Vortex body as a kinematic Unity rigid body, which acts upon other Unity objects but is not acted upon, all that is required is to add a RigidBody component with is Kinematic set to true to the Vortex mechanism prefab. Specifically, the component should be added as a child of a Game Object with a Vortex Node script, so that the transform of the kinematic Rigidbody can be automatically updated. For example, below we add a kinematic Rigidbody to the Chassis of a SportsCarMechanism prefab:
To actually enable collisions with this rigid body, a few options are available:
Add a collider to the same Game Object that contains the Rigidbody component. While this works, the collisions are often not very springy. This can be an option if the Vortex mechanism only moves slowly, or if it is often stationary.
Add another game object to the prefab with a collider and a Rigidbody component connected by a Fixed Joint to the kinematic Rigidbody. This is a good option for a very dynamic mechanism, such as the sports car vehicle below.
The mass of the Rigidbody should not be the same as the mass of the mechanism. Rather, it should be close (within a factor of 10) to the mass of the objects with which you wish to collide for springy collisions. If this mass is too large or too small compared to the colliders, the collisions will be of poor quality, as in the previous option.
Unity->Vortex Transfer
To enable the Unity->Vortex transfer, first, in the Unity editor, navigate to the Vortex Scene GameObject. In the inspector for this GameObject you will see the ‘Vortex Kinematics’ component. This contains a single field, which allows you to select the layers which contain the objects you wish to stream to Vortex. Simply set the layers in the Vortex Kinematics component, and the feature will be active.
A layer for this task can be defined in Unity to organize the GameObjects which are to be streamed into Vortex, if an appropriate layer does not already exist. To do this, navigate to the Tags and Layers tab of the project settings.
Above, you can see a number of layers used for Vortex physics interfacing have been defined. The AnimatedColliders layer is what we are concerned with now. This layer is to contain all the objects which move that should be streamed to Vortex.
To have GameObjects which move in Unity streamed into Vortex so that they may interact with Vortex mechanisms there are three requirements
The GameObject must have a rigid body component.
The GameObject must have a collider.
The GameObject must be in a layer which has been selected for physics transfer.
The first two criteria will often be satisfied by objects which are to be streamed to Vortex as most objects which take part in Unity physics interactions will have a rigid body and a collider. The latter requires that the layer which the GameObject is in should be included in the Layers option of the VortexKinematics component on the Vortex Scene GameObject. These objects will now be streamed into Vortex and have their positions, orientations and velocities updated to match those of the corresponding object in Unity.
Layer Management
For the physics interfacing, we have described adding a layer to contain the objects which are to be streamed to Vortex from Unity. However, when using the Vortex->Unity transfer and Unity->Vortex transfer simultaneously problems can arise.
If all the default settings will use, Colliders attached to Vortex Mechanisms in Unity will collide with GameObjects that are to be streamed into Vortex. This is problematic as the collisions create a closed loop and can often produce unexpected behavior.
The solution is to define a VortexMechanisms layer to which all Vortex Mechanisms can be added. The layer matrix of the Physics tab in the Unity project settings can then be used to discard collisions between objects in certain layers. In this case, we disable the collisions between the VortexMechanisms layer and the AnimatedColliders, Terrain and VortexMechanisms layer.
This has the following effects:
As a VortexMechanism cannot collide with an AnimatedCollider, it is not possible to form a closed loop in the physics transfer. Either the object can be pushed by the VortexMechanism’s collider, or it is streamed into Vortex, but not both.
As a VortexMechanism cannot collide with the terrain in Unity, we improve the performance as these contacts will be ignored. The interaction between the VortexMechanism and the terrain occurs in Vortex.
As VortexMechanisms cannot collide with each other in Unity, we improve the performance, as these contacts will be ignored. The interaction between the VortexMechanisms occurs in Vortex.
So, layers can be used to ensure that collisions take place on the correct side of the interface, either collisions take place between objects in Unity, in which case the Unity dynamic object should not be streamed into Vortex, or, the collision takes place in Vortex, in which case the object should be streamed into Vortex, but collisions between those objects in Unity should be disallowed.
Usage and Performance Guidelines
Vortex->Unity Physics Transfer
When you are interested in colliding with a large number of objects simultaneously and the fidelity of the collisions is not important, the Vortex->Unity exchange provides a huge gain in performance over simulating the objects entirely in Vortex. Up to a 10x increase in the number of colliders interacting simultaneously can be expected.
Unity->Vortex Physics Transfer
The processing of animated colliders proceeds in a way analogous to the processing of static colliders, except animated collider state is updated every frame instead of once per tile query. For a moderate number of colliders (10-50), the compute overhead is ~0.5 ms, going up to ~ 1 ms for ~100 colliders.