This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.
        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
                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.

in Engine by (17 points)
edited by

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

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.

1 Answer

0 votes

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

by (189 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.