This section describes how to create and trigger advanced haptic patterns with Nice Vibrations.

What are advanced patterns?

Advanced patterns are a way to play very specific haptic patterns, with complete control over intensity and sharpness over time. Based on the AHAP format introduced by iOS, Nice Vibrations also offers a way to play these on Android, with slightly less fidelity as Android doesn’t offer sharpness control (yet).

Advanced patterns are composed of continuous and haptic patterns of various intensity and sharpness, and can be represented like so :

Jekyll
And example of a advanced pattern

Creating an advanced pattern

Advanced patterns are defined by a JSON format called AHAP (Apple Haptic and Audio Pattern). They are usually designed to mimic a sound in haptic form (but you can use them to do whatever you want, not just mimic sound). These files are usually hundreds of lines long, and creating them by hand can be quite tedious. Fortunately, there are free editors out there that make this process a breeze. I’d recommend using Lofelt Composer, but any editor that outputs correct AHAP will do.

Playing an advanced pattern using Nice Vibrations

You can either feed nice vibrations with a giant string containing the contents of your AHAP json, or you can just store your file as a json file somewhere - that’s obviously the recommended way :). So once you’ve got your AHAP file, you’ll want to rename it to a .json extension, and put it somewhere in your project. Then, in the class where you want to trigger your AHAP pattern, just declare a TextAsset, like so :

public TextAsset AHAPFile;

You can now play this from any method in your class, like this :

MMVibrationManager.AdvancedHapticPattern("test", null, null, -1, null, null, null, -1, HapticTypes.LightImpact);       

As you can see in the API documentation, the first parameter is your AHAP content as a string, the two next ones are Android patterns and amplitude, followed by Android repeat rule, and finally a fallback to use in case advanced patterns aren’t supported.

Converting AHAP to Android

If you want to also support Android, you’ll want to convert your AHAP to an Android Waveform. This is made quite easy by Nice Vibrations. To do so, in any folder of your choice, just right click and go Create > MoreMountains > NiceVibrations > AndroidWaveFormAsset, and give it the name of your choice.

Jekyll
Creating an advanced pattern asset for Android

Then select the newly created asset, drag your AHAP .json file in the AHAPFile slot in its inspector, and press the “Import from AHAP” button. That’s it!

Jekyll
Importing from AHAP

Then to play it, just declare it in your class like you did for the AHAP file :

public MMNVAndroidWaveFormAsset WaveFormAsset;

And when playing the file, using the same method as before, you can now add Android specific values, like so :

MMVibrationManager.AdvancedHapticPattern(AHAPFile.text, WaveFormAsset.WaveForm.Pattern, WaveFormAsset.WaveForm.Amplitudes, -1, null, null, null, -1, HapticTypes.LightImpact);        

Converting AHAP to gamepad

If you want to also support gamepads, you’ll want to convert your AHAP to a Rumble Waveform. To do so, in any folder of your choice, right click and go to Create > MoreMountains > NiceVibrations > RumbleWaveFormAsset, and give it the name of your choice. Then select the newly created asset, drag your AHAP .json file in the AHAPFile slot in its inspector, and press the “Import from AHAP” button. You’re done!

Now to play it :

MMVibrationManager.AdvancedHapticPattern(iOSString, androidPattern, androidAmplitude, AndroidRepeat,                                                                        rumblePattern, lowFreqAmplitude, highFreqAmplitude, RumbleRepeat, HapticTypes.LightImpact, this);