- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
zaniar · Apr 04, 2015 at 08:34 PM ·
androidrotateaccelerometeracceleration
Rotate Camera using Accelerometer
Hi , i want rotate Camera using Acceleration in Landspace orientation . Following Code work in dir.y fine but in dir.x only work when Phone is flat . When Phone is in Landspace-Vertical Camera just rotate up and for rotate down i must flat Phone (input.y=0 to -) then rotate down . Actully must sense tlit forward and backward in Vertial-Landspace-Orientation (not flat) . any Idea? , Thanks .
accerangex=Mathf.Abs(-Input.acceleration.y);
accerangey=Mathf.Abs(Input.acceleration.x);
Vector3 dir = Vector2.zero;
dir.x = -Input.acceleration.y ;
dir.y = Input.acceleration.x ;
if (dir.sqrMagnitude >1)
dir.Normalize();
dir *= Time.deltaTime;
if (accerangex < 0.82){
transform.Rotate(dir.x * 2, 0 , 0);
}
if (accerangey > 0.1){
transform.Rotate(0 , dir.y * 20 , 0);
}
Comment