I make a telegram game uesd get_accelerometer, but it's too bad

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

enter image description here

This is my code:

extends Node2D

var low = -1.5
var current = false
var timer = 0.0
var code = ""

# Called when the node enters the scene tree for the first time.
func _ready():
	low = Input.get_accelerometer().x

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	var threshold
	var accX = Input.get_accelerometer().x
	
	if current:
		threshold = low+0.2
		timer = timer + delta    #When pressdown, it will be timing.
	else:
		threshold = low+0.4
		if timer > 0:        #When pressup, it will be calculate the duration of the press.
			if timer > 0.2:
				code = code + "-"    #long
			else:
				code = code + "."    #short
		timer = 0
	
	$console.text = code 
	current = accX > threshold    #Detect pressing

func _on_calibration_pressed():
	low = Input.get_accelerometer().x

When I click the phone, it show irregular garbled. I guess the gyroscope sensor is not accurate enough.

I don’t know where the problem is.
Maybe my code isn’t good enough, maybe I should add low-pass filtering. maybe it’s a bad idea to simulate a telegram with gyroscope sensor.

You didn’t say what the problem is. What does it do, or not do, that’s the issue?

jgodfrey | 2020-02-22 03:41

When I click the phone, it show irregular garbled. I guess the gyroscope sensor is not accurate enough.

Btw, I use a old Nexus5 phone test my game.

NoIE | 2020-02-22 12:03

:bust_in_silhouette: Reply From: code

I am also making a game that make use of accelerometer and mine is working perfectly
The code I am using is this

var direction = Input.get_accelerometer() / 10

Direction show me the direction the phone is been tilted to
U just multiple it by ur speed and put it in a move and slide function and u are good to go