boltVibration

This template includes a lightweight Vibration System that provides haptic feedback across supported platforms. The system is designed to be simple, extensible, and accessible from any part of the project via dependency injection.

Supported Platforms

  • Android

  • IOS

circle-info

Note: Actual vibration behavior may vary depending on the device and OS version.

Registration and Dependency Injection

The vibration functionality is implemented in the Vibration class.

Class location:

Asset/KrolStudio/SwipeGunner/Scripts/Runtime/Services/Vibration/...

An instance of Vibration is created during game initialization in the GameInstaller and bound to the ProjectContext container. This makes the service globally available throughout the project.

Container.Bind<Vibration>().AsSingle();

The dependency is injected via constructor injection, for example:

namespace KrolStudio
{
    public class YourClass : MonoBehaviour
    {
        Vibration vibration;

        [Inject]
        void Construct(Vibration vibration)
        {
            this.vibration = vibration;
        }
}

Triggering Vibration

To trigger a vibration effect, call the Vibrate method on the injected Vibration instance:

vibration.Vibrate(GameConstants.Vibrations.ShortVibration);

The parameter defines the vibration duration in milliseconds.

Vibration Duration Constants

Predefined constants are provided for common use cases:

You can define additional durations if needed, depending on gameplay or UX requirements.

Notes & Recommendations

  • Use short vibrations for frequent feedback (UI interactions, light hits).

  • Reserve longer vibrations for important events (fail states, rewards).

  • Avoid excessive vibration calls to prevent user fatigue.

  • Always test vibration behavior on real devices.

Last updated