Class BhapticsLibrary
class BhapticsLibrary contains the functions for using haptic devices from bHaptics.
References
- Path: Assets\Bhaptics\SDK2\Scripts\Core\Plugins\BhapticsLibrary.cs
Static Functions — Play Event-driven Haptic
Play the haptic patterns bound to specific haptic event made from Designer/Portal. We highly recommend to use these functions.
Play
public static int Play(string eventId, int startMillis = 0, float intensity = 1f, float duration = 1.0f, float angleX = 0.0f, float offsetY = 0.0f);
Play haptic event, with adjusting the strength, duration, and direction of the haptic.
Parameters
string eventId: Name of haptic event which you want to play.int startMillis: Windows/Android Only The delay in milliseconds before the haptic event starts playing. The haptic will begin after this time has elapsed.float intensity: The haptic intensity is multiplied by this value.float duration: The haptic duration is multiplied by this value.float angleX: Rotate haptic counterclockwise around the globalVector3.up. Valid range is: [0.0f-360.0f]float offsetY: Move haptic up or down. Valid range is: [-0.5f-0.5f]
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
public class Example : MonoBehaviour
{
private void OnShoot()
{
// Assume the event name is "shootpistol"
// BASIC USAGE
BhapticsLibrary.Play(BhapticsEvent.SHOOTPISTOL);
// or
BhapticsLibrary.Play("shootpistol");
// ADVANCED USAGE
BhapticsLibrary.Play(
BhapticsEvent.SHOOTPISTOL, // Haptic name
0, // Delay Time (millisecond)
1.0f, // Haptic intensity
1.0f, // Haptic duration
20.0f, // Rotate haptic around global Vector3.up (0f - 360f)
0.3f // Move haptic up or down (-0.5f - 0.5f)
);
}
}
PlayParam
public static int PlayParam(string eventId, float intensity, float duration, float angleX, float offsetY);
Play haptic event, with adjusting the strength, duration, and direction of the haptic.
Parameters
string eventId: Name of haptic event which you want to play.float intensity: The haptic intensity is multiplied by this value.float duration: The haptic duration is multiplied by this value.float angleX: Rotate haptic counterclockwise around the globalVector3.up. Valid range is: [0.0f-360.0f]float offsetY: Move haptic up or down. Valid range is: [-0.5f-0.5f]
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
public class Example : MonoBehaviour
{
private void OnShoot()
{
BhapticsLibrary.PlayParam(
BhapticsEvent.SHOOTPISTOL, // Haptic name
1.0f, // Haptic intensity
1.0f, // Haptic duration
20.0f, // Rotate haptic around global Vector3.up (0f - 360f)
0.3f // Move haptic up or down (-0.5f - 0.5f)
);
}
}
PlayLoop
public static int PlayLoop(
string eventId,
float intensity = 1.0f,
float duration = 1.0f,
float angleX = 0.0f,
float offsetY = 0.0f,
int interval = 200,
int maxCount = 999999
);
Play the haptic repeatedly. Additionally, like the function PlayHapticWithOption, you can adjust the strength, duration, and direction of the haptic.
Parameters
string eventId: Name of haptic event which you want to play.float intensity: The haptic intensity is multiplied by this value.float duration: The haptic duration is multiplied by this value.float angleX: Rotate haptic counterclockwise around the globalVector3.up. Valid range is: [0.0f-360.0f]float offsetY: Move haptic up or down. Valid range is: [-0.5f-0.5f]int interval: The time interval between loops, measured in milliseconds.int maxCount: The number of loops.
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
public class Example : MonoBehaviour
{
private void OnShoot()
{
BhapticsLibrary.PlayLoop(
BhapticsEvent.SHOOTPISTOL, // Haptic name
1.0f, // Haptic intensity
1.0f, // Haptic duration
20.0f, // Rotate haptic around global Vector3.up (0f - 360f)
0.3f // Move haptic up or down (-0.5f - 0.5f)
200, // Loop interval time (millisecond)
999999 // Loop count
);
}
}
Static Functions — Play Haptic Directly
If you want to play haptics without creating a new event, use these functions.
PlayMotors
public static int PlayMotors(int position, int[] motors, int durationMillis);
Play haptic feedback on the specific haptic actuator. You can use this function without creating an event.
Parameters
int position: Type of haptic device. For more information, please refer here.Value Device Same as... Motors Count 0TactSuit Pro PositionType.Vest32 1TactSleeve(Left) PositionType.ForearmL3 2TactSleeve(Right) PositionType.ForearmR3 3TactVisor PositionType.Head4 4Tactosy for Hands(Left) PositionType.HandL6 5Tactosy for Hands(Right) PositionType.HandR6 6Tactosy for Feet(Left) PositionType.FootL6 7Tactosy for Feet(Right) PositionType.FootR6 8TactGlove(Left) PositionType.GloveL6 9TactGlove(Right) PositionType.GloveR6 int[] motors: Assign the length of the array by the number of motors for device. Values in the array means motors' intensity. Valid range for each value in the array is: [1-100]int durationMillis: The duration of haptic, measured in millisecond. Greater than or equal to100is recommended.
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
public class Example : MonoBehaviour
{
private void OnCall()
{
// TactSuit Pro has 32 motors, so length of array should be 32 too.
int[] MotorValueArray = new int[] {
50, 40, 30, 20, 10, 50, 40, 30,
50, 40, 30, 20, 10, 50, 40, 30,
50, 40, 30, 20, 10, 50, 40, 30,
50, 40, 30, 20, 10, 50, 40, 30,
};
BhapticsLibrary.PlayMotors(
(int)PositionType.Vest, // Device type
MotorValueArray, // Haptic intensities
500 // Haptic duration (millisecond)
);
}
}
PlayWaveform
public static int PlayWaveform(
PositionType positionType,
int[] motorValues,
GlovePlayTime[] playTimeValues,
GloveShapeValue[] shapeValues
);
TactGlove Only. Play haptics in TactGlove. Unlike using PlayMotors, you can finely adjust haptic duration and vibration intensity changes. This allows for even finer expression of haptic feedback.
Each array must have six elements, and at least one element is required to work.
Parameters
-
PositionType positionType: Type of haptic device.Value Device Same as… PositionType.GloveLTactGlove(Left) 8PositionType.GloveRTactGlove(Right) 9 -
int[] motorValues: An array consisting of six elements, each representing the intensity of a motor. The array must have a length of six, as there are six motors in one TactGlove. Valid range for each value in the array is: [1-100]Array Index Motor is positioned at… 0Tip of the thumb 1Tip of the index finger 2Tip of the middle finger 3Tip of the ring finger 4Tip of the little finger 5On the wrist -
GlovePlayTime[] playTimeValues: An array consisting of six elements, each representing a time interval for actuation, with time defined usingGlovePlayTimeenums.Value Duration Same as… GlovePlayTime.NoneNone 0GlovePlayTime.FiveMS5ms 1GlovePlayTime.TenMS10ms 2GlovePlayTime.TwentyMS20ms 4GlovePlayTime.ThirtyMS30ms 6GlovePlayTime.FortyMS40ms 8 -
GloveShapeValue[] shapeValues: An array consisting of six elements, each representing the forms of haptic intensity changes over time, specified by theGloveShapeValueenums.Value Waveform Same as… GloveShapeValue.ConstantConstant intensity for the duration 0GloveShapeValue.DecreasingStarts at the specified intensity and decreases by half 1GloveShapeValue.IncreasingStarts at half of the specified intensity and increases to the specified one. 2
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
public class TestHaptic : MonoBehaviour
{
public void OnCall()
{
int[] motorValues = new int[6] { 50, 80, 100, 0, 0, 0 };
GlovePlayTime[] playTimeValues = new GlovePlayTime[6] {
GlovePlayTime.FiveMS, GlovePlayTime.TwentyMS,
GlovePlayTime.ThirtyMS, GlovePlayTime.None,
GlovePlayTime.None, GlovePlayTime.None
};
GloveShapeValue[] shapeValues = new GloveShapeValue[6] {
GloveShapeValue.Constant, GloveShapeValue.Decreasing,
GloveShapeValue.Increasing, GloveShapeValue.Constant,
GloveShapeValue.Constant, GloveShapeValue.Constant
};
BhapticsLibrary.PlayWaveform(
PositionType.GloveL, // Device Type
motorValues, // Intensities
playTimeValues, // Intervals
shapeValues // Intensity changing forms
);
}
}
PlayPath
public static int PlayPath(
int position,
float[] xValues,
float[] yValues,
int[] intensityValues,
int duration
);
Play haptic around specific coordinates. Unlike PlayMotors function, which specifies the haptic intensity for each haptic actuator individually, this method specify the haptic intensity for particular coordinates.
When specifying haptic position, PlayMotors offers discrete control, while PlayPath is more continuous. PlayMotors assigns intensity to individual actuators, whereas PlayPath allows intensity specification for specific coordinates (between 0 and 1 for both X and Y axis), causing nearby actuators to vibrate accordingly.
You can put multiple coordinates with multiple intensities. Note that all actuators around these coordinates in the array will activate simultaneously (at the same time), not sequentially. Moreover, the size of all arrays must be the same.
By continuously calling this function while gradually changing the values, you can achieve the effect of a moving haptic point.

Parameters
int position: Type of haptic device.Value Device Same as... 0TactSuit Pro PositionType.Vest1TactSleeve(Left) PositionType.ForearmL2TactSleeve(Right) PositionType.ForearmR3TactVisor PositionType.Head4Tactosy for Hands(Left) PositionType.HandL5Tactosy for Hands(Right) PositionType.HandR6Tactosy for Feet(Left) PositionType.FootL7Tactosy for Feet(Right) PositionType.FootR8TactGlove(Left) PositionType.GloveL9TactGlove(Right) PositionType.GloveRfloat[] xValues: Assign X coordinate. Valid range for each value in the array is: [0.0f-1.0f]float[] yValues: Assign Y coordinate. Valid range for each value in the array is: [0.0f-1.0f]int[] intensityValues: Assign the length of the array by the number of coordinate. Values in the array means coordinates' intensity. Valid range for each value in the array is: [1-100]int duration: The duration of haptic, measured in millisecond. Greater than or equal to100is recommended.
Returns
Request ID. You can use the request ID to stop the haptic. It returns -1 if the return fails.
However, when connected to the Hub, failed calls do not return -1 because the Hub does not provide a return value.
Example
using Bhaptics.SDK2;
/* Assumption:
- For TactSuit
- Coordinate with Intensity
- (X: 0.1, Y: 0.2) Intensity 40
- (X: 0.3, Y: 0.4) Intensity 80
- (X: 0.5, Y: 0.6) Intensity 10
- Duration 500ms(=0.5 second)
*/
public class TestHaptic : MonoBehaviour
{
public void OnCall()
{
BhapticsLibrary.PlayPath(
(int)PositionType.Vest, // Device type
new float[] { 0.1f, 0.3f, 0.5f }, // X Coordinates
new float[] { 0.2f, 0.4f, 0.6f }, // Y Coordinates
new int[] { 40, 80, 10 }, // Intensities
500 // Duration
);
}
}
Static Functions — Others
using Bhaptics.SDK2;
public class TestHaptic : MonoBehaviour
{
public void OnCall()
{
int requestID = BhapticsLibrary.Play("TestHaptic");
if (BhapticsLibrary.IsPlayingByEventId("TestHaptic"))
{
BhapticsLibrary.StopByEventId("TestHaptic");
}
if (BhapticsLibrary.IsPlayingByRequestId(requestID))
{
BhapticsLibrary.StopInt(requestID);
}
if (BhapticsLibrary.IsPlaying())
{
BhapticsLibrary.StopAll();
}
}
}
StopByEventId
public static bool StopByEventId(string eventId)
Stop the haptic event by Event ID. Returns whether the stop was successful.
StopInt
public static bool StopInt(int requestId)
Stop the Haptic Event by using the Request ID from the return of the function that executes the haptic. Returns whether the stop was successful.
StopAll
public static bool StopAll()
Stops all haptic currently playing. Returns whether the stop was successful.
IsPlaying
public static bool IsPlaying()
Check if any haptic is currently playing.
IsPlayingByEventId
public static bool IsPlayingByEventId(string eventId)
Check if the haptic event for this Event ID is currently playing.
IsPlayingByRequestId
public static bool IsPlayingByRequestId(int requestId)
Check if the haptic event for this Request ID is currently playing.
PauseByEventId
public static void PauseByEventId(string eventId)
Pauses an active haptic event. Use PauseByEventId(string eventId) to pause a specific haptic event. The paused event can later be resumed using ResumeByEventId(string eventId).
ResumeByEventId
public static void ResumeByEventId(string eventId)
Resumes a paused haptic event. Use ResumeByEventId(string eventId) to resume playback from the position it was paused at.