0 votes

Hello everyone,
I have a problem with the control handling for mobile devices.
I want my character to move when I move my phone, like driving in a racing game.
Thanks already to those who will answer.
Good continuation to all.

Godot version Godot 3.2.2
in Engine by (12 points)

1 Answer

0 votes

Generally, you're looking for Input.get_accelerometer().

See the docs here:

https://docs.godotengine.org/en/stable/classes/class_input.html#class-input-method-get-accelerometer

A simple use could look like this:

func _process(delta):
    var pos = position

    if Globals.isMobile:
        vel.x = MOVE_SPEED * Input.get_accelerometer().x * 0.4

    position += vel * delta
by (12,290 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 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 webmaster@godotengine.org with your username.