Haptic touch on mobile?

Hey, so I’m trying to utilize haptic feedback for mobile users (or at least those with compatible devices) when an interface button is pressed. I didn’t think it was possible until I played this on my phone and tapped on the buttons onscreen. I attempted using HapticService, but I’m not sure how to get the desired result. I tried using :IsMotorSupported and :IsVibrationSupported with Enum.UserInputType.Touch, but it returns false. How do I go about getting this to work?

I’m pretty sure haptic feedback is only for controllers. That is probably why you are getting false.

Yeah, the documentation for HapticService states it being used for controllers. How did that game manage to vibrate my phone when I tapped the buttons? I’m not sure.

Did you try using the same phone that vibrated when you played that game?

Same phone (iPhone 14 Pro Max). I had made a place to print the results, and all returned false. Were you able to play the game and feel the haptic feedback simply tapping the buttons?

Which phone were you on?
Refer to this:

I haven’t tested it on my phone yet. I will try it later.

Haptic Feedback works on my phone. I haven’t testing the other motor enums, but the .Enum.VibrationMotor.Large motor works. My phone is a Motorola 5G Stylus 2021.

I don’t do any checks for if the player has vibration support, I just run the code if the player has the option in my settings menu enabled.

part 1 - local script
local uis = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")

local UseHapticFeedback = game.Workspace.RemoteEventsFolder.UseHapticFeedback
local toggle_isHapticFeedbackEnabled_RemoteEvent = game.Workspace.RemoteEventsFolder.OptionsMenuToggles.ToggleHapticFeedbackSetting

local isHapticFeedbackEnabled = true
UseHapticFeedback.OnClientEvent:Connect(function(whatMotorShouldBeMoving,howLongShouldTheRumbleLast,howIntenseShouldTheRumbleBe)
	if isHapticFeedbackEnabled == true then
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, whatMotorShouldBeMoving, howIntenseShouldTheRumbleBe)
		task.wait(howLongShouldTheRumbleLast)
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, whatMotorShouldBeMoving, 0)
	else
		warn("Player does NOT have haptic feedback enabled.")
	end
	
end)

toggle_isHapticFeedbackEnabled_RemoteEvent.OnClientEvent:Connect(function(toggleState)
	isHapticFeedbackEnabled = toggleState
end)

part 2 - server script
local UseHapticFeedback = game.Workspace.RemoteEventsFolder.UseHapticFeedback

local howLongShouldTheRumbleLast = 0.25
local howIntenseShouldTheRumbleBe = 0.35
local whatMotorShouldBeMoving = Enum.VibrationMotor.Large
				
UseHapticFeedback:FireAllClients(whatMotorShouldBeMoving,howLongShouldTheRumbleLast,howIntenseShouldTheRumbleBe)

For the server script, I have it under a touched event from when the player rams into crates and walls of rock.

Also, you’d need to adapt the code/remove some stuff. I use remote events and whatnot. That’s just the code from my game PB & Jay.

2 Likes

Gotcha, yeah, my phone does vibrate when using Enum.UserInputType.Gamepad1. Mobile touches aren’t natively supported hence why it returns false, but I could still simulate one by using that input type and run some code that lets out a small burst of feedback when a UI element is tapped. I should’ve thought of that, thanks!

2 Likes

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