Anyone use "HapticService" for Mobile currently? | iPhone 14

HapticService for Mobile devices - Feature Requests / Mobile Features - Developer Forum | Roblox

I’ve read the thread above, seems like it’s a thing.

Here’s my Haptic Feedback, it’s just not firing the vibration despite doing everything, and the prints work.

Anyone developers have experience with firing these? I hate loading up my iPhone to not get any haptics.

It fires fine via the ‘ROBLOX Studio Mobile Testing Client’, but I don’t see any controls, does anyone know how to get this going?

Haptic Feedback Module:

local HapticFeedback = {}
local HapticService = game:GetService("HapticService")

function HapticFeedback.triggerMediumVibration()
	task.spawn(function()
	if game:GetService("UserInputService").TouchEnabled then
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 1)
			task.wait(1)
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0)
		else end end)
end

function HapticFeedback.triggerLowVibration()
	task.spawn(function()
	if game:GetService("UserInputService").TouchEnabled then
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0.5)
			task.wait(0.2)
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0)
	else end end)
end

function HapticFeedback.triggerCriticalVibration()
	task.spawn(function()
	if game:GetService("UserInputService").TouchEnabled then
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 1)
			task.wait(2)
			HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0)
		else end end)
end
function HapticFeedback.triggerSpecialVibration()
	task.spawn(function()
	if game:GetService("UserInputService").TouchEnabled then
			for i = 1, 3 do
				HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 1)
				task.wait(0.3)
				HapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0)
				task.wait(0.3)
			end
		else end end)
end

function HapticFeedback.__init()
-- this is fine, this isn't an issue. I can fire, cast, and use this fine, but it doesn't wanna make my [Haptic] work. lol.
end

return HapticFeedback
2 Likes

Yeah when did Roblox say HapticService was available on mobile

Just pull out 70 phones and check if they support vibration by using IsVibrationSupported or whatever.

I never even realised HapticService was a thing despite having played on mobile for ages, never seen a game use it.

It may just be one of those features ROBLOX uses and didn’t patch specifically? Idunno, let me fix it, hire me rblx

If Roblox says it’s up…

I’ll try tomorrow. This might be useful for me, if it works…

1 Like

Yo, if anyone or you can get Haptics on any device I guess to work, wanna let me know…

I don’t wanna pull up my iPhone and test haptics today, but if it works, maybe I’m doing something wrong via my iPhone settings.

Additionally, I’ll post an update if I get this running.

EDIT: 7:56am
I think it could be a motor setting or something, I have other more important systems to program for my game today, so I don’t want to hold up on this.

It could be a Motor setting, lol:

I’ll play with the isMotorSupported and cast a visual UI open to see if it should be firing.

This system for my game isn’t mandatory, but would be a really awesome feature for my mobile players & Console. -[[yes, i know my code doesn’t have console in mind yet]]-

Hey,

We use HapticService for our generic buttons and offer mobile support (tested on iPhone 12 Pro Max, iPhone 13 Pro Max, 14 Pro Max). We give 8 haptic vibration options and they play for a very short period of time (talking a couple frames) but I should be able to help you out.

We don’t check if IsVibrationMotorSupported because I found it a bit of a hassle to set up at the time but should probably set it up going forward but I digress.

I don’t remember where I saw it but I did see somewhere that vibrations on mobile will only work with the Gamepad1 UserInputType, not touch which is why you aren’t receiving any haptic feedback. We do set the motor’s vibration intensity for the touch InputType as a fallback but in most if not all cases you will need to use Gamepad1, not Touch. It’s quite a mess but it works:

local OPTIONS_PRESETS = {
	[0] = {
		[Enum.VibrationMotor.Small] = 0;
		[Enum.VibrationMotor.Large] = 0;
	};
	[1] = {
		[Enum.VibrationMotor.Small] = 0.25;
		[Enum.VibrationMotor.Large] = 0;
	};
	[2] = {
		[Enum.VibrationMotor.Small] = 0.5;
		[Enum.VibrationMotor.Large] = 0;
	};
	[3] = {
		[Enum.VibrationMotor.Small] = 0.75;
		[Enum.VibrationMotor.Large] = 0;
	};
	[4] = {
		[Enum.VibrationMotor.Small] = 1;
		[Enum.VibrationMotor.Large] = 0;
	};
	[5] = {
		[Enum.VibrationMotor.Small] = 0;
		[Enum.VibrationMotor.Large] = 0.25;
	};
	[6] = {
		[Enum.VibrationMotor.Small] = 0;
		[Enum.VibrationMotor.Large] = 0.5;
	};
	[7] = {
		[Enum.VibrationMotor.Small] = 0;
		[Enum.VibrationMotor.Large] = 0.75;
	};
	[8] = {
		[Enum.VibrationMotor.Small] = 0;
		[Enum.VibrationMotor.Large] = 1;
	};
}

local lastHaptic

function module:PlayHaptic()
	local optionsHandler = require(clientInitializer):GetModule('OptionsHandler')
	local option = optionsHandler:GetOptionValue('Haptics').Value
	local now = tick()
	lastHaptic = now
	hapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Small, OPTIONS_PRESETS[option][Enum.VibrationMotor.Small])
	hapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, OPTIONS_PRESETS[option][Enum.VibrationMotor.Large])

	hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, OPTIONS_PRESETS[option][Enum.VibrationMotor.Small])
	hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, OPTIONS_PRESETS[option][Enum.VibrationMotor.Large])
	
	task.delay(HAPTIC_LENGTH, function()
		if lastHaptic == now then
			hapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Small, 0)
			hapticService:SetMotor(Enum.UserInputType.Touch, Enum.VibrationMotor.Large, 0)

			hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 0)
			hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
		end
	end)
end

Here’s an uncopylocked place I made a while ago that does this if you need a working demo:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.