how to implement android vibration?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hermo

I’m testing a game for android.

When I try to implement the vibration I get this error: the method vibrate_handheld isn’t declared in the current class.

The only thing about vibration I coud find was here

This is my code (if i remove the vibrate line it works perfectly on both windows and android):

func _physics_process(delta):
	$score.set_text(str(score))
	
	if Input.is_mouse_button_just_pressed(1):
		score += 1
		vibrate_handheld(500)

I know I’m doing something wrong in that last line but I dont know how to put the vibration method.

Thank you very much!

:bust_in_silhouette: Reply From: goodeb

The vibrate_handheld function is a method of the Input class. Change that line of code to look like this

Input.vibrate_handheld(500)

that worked perfectly! thank you very much!!!

hermo | 2020-05-08 10:17

1 Like