2
\$\begingroup\$

I'm used the Handheld.Vibrate() method. I know that if you call it several times, you can increase the vibration time, but when it is called once, the vibration lasts about 1 second. But I would like to make an imitation of clicking on the android keyboard. (Vibration ~ 0.2s)

How to set the duration of the vibration?

\$\endgroup\$
5
  • \$\begingroup\$ What platform are you targeting? (I do not think there is a platform agnostic solution) \$\endgroup\$
    – Theraot
    Nov 30, 2019 at 3:22
  • \$\begingroup\$ After looking around the Unity community, apparently the recommendation is to get a plug-in from the Asset Store. You can find them under "Tools" -> "Integration", search for "Vibration" or "Haptic Feedback". \$\endgroup\$
    – Theraot
    Nov 30, 2019 at 4:00
  • \$\begingroup\$ basically ios has many different types of vibration but android has only basic vibration. in unity only HandHeld.Vibrate() works in both of them. that vibrates phone in 0.5 seconds. if you you want to vibrate in a wanted length, just make a coroutine thatvibrates phone in wanted seconds \$\endgroup\$
    – virtouso
    Nov 30, 2019 at 6:57
  • \$\begingroup\$ @Theraot that looks like an upvote-worthy answer, especially if you can include a summary of one of these plug-ins or citation of this recommendation. \$\endgroup\$
    – DMGregory
    Nov 30, 2019 at 13:39
  • \$\begingroup\$ @virtouso as we can read in OP's question, they want a shorter vibration than the default, not a longer one. \$\endgroup\$
    – DMGregory
    Nov 30, 2019 at 13:40

2 Answers 2

2
\$\begingroup\$

You can use this script, which calls the native Android API:

https://gist.github.com/ruzrobert/d98220a3b7f71ccc90403e041967c46b

The author allows commercial use and even adopting the script

The script provides a lot of options, e.g.

// vibrating for 500 milliseconds with an amplitude of 50
Vibration.Vibrate(100, 50)

// using predefined effects
VibratePredefined(1)

iOS doesn't seem to provide any methods for finer control than Handheld.Vibrate().

\$\endgroup\$
-4
\$\begingroup\$
void Start()
{
    StartCoroutine(VibrateDuration());
}

public IEnumerator VibrateDuration()
{
    yield return new WaitForSeconds(2.0f);
    Handheld.Vibrate();
}
\$\endgroup\$
1
  • 4
    \$\begingroup\$ This waits 2 seconds then vibrates for the default duration. It does not demonstrate how to vibrate for a shorter duration as the question asks. \$\endgroup\$
    – DMGregory
    Jul 7, 2020 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .