Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

How to calibrate accelerometer according to start ?

$
0
0
I think i have a "should be" working code but i don't know why it is not working. With this code too i have to hold the phone straight to get it to work. My present code is below. Any help is appreciated :) #pragma strict var speed : float; var accelerationX : float = 0; var accelerationZ : float = 0; var zatstart : float = 0; function Start () { zatstart = Input.acceleration.z; } function Update () { var dir : float; dir = (Input.acceleration.z-zatstart); if (dir > 1){ dir = 1; } accelerationX = Input.acceleration.x; accelerationZ = -1*(dir); GetComponent.().AddRelativeForce(new Vector3(accelerationX * speed,0,accelerationZ * speed)); }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>