0 votes

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?

in Engine by (23 points)

1 Answer

0 votes

Maybe this can help you out:
"A demo showing the use of various sensors: a accelerometer, a gyroscope and a magnetometer."
https://github.com/godotengine/godot-demo-projects/tree/3.0-d69cc10/misc/sensors

You can also find it at the Templates tab on the Project Manager Window.
Just search for "sensors" (without quotes, of course.... :) )
enter image description here
enter image description here

by (14 points)
edited by
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.