How to make 3d movement with accelerometer?

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

I have 3d game, and i don’t know how to input accelerometer. I’m trying to input this script but doesn’t working good

extends KinematicBody
var gravity = Vector3.Down*25
var speed = 8 
var velocity = vector3()

func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity, Vector3.UP)

func get_input():
velocity.x = 0
velocity.y = 0
if Input.get_accelerometer().x<0:
       velocity.x -= speed
if Input.get_accelerometer().x<0:
       velocity.x += speed
if Input.get_accelerometer().z<0:
       velocity.z += speed
if Input.get_accelerometer().z<0:
       velocity.z -= speed

How to make better?

:bust_in_silhouette: Reply From: rodexan

Maybe this can help you out:
“A demo showing the use of various sensors: a accelerometer, a gyroscope and a magnetometer.”

You can also find it at the Templates tab on the Project Manager Window.
Just search for “sensors” (without quotes, of course… :slight_smile: )