unity3d - Unity (iOS) device angle on one axis -


i'm creating game in unity takes input physical rotation of device , turns force applied main character (a ball). using input.acceleration works fine, , added z-axis offset can choose default "up" it, 45 degrees table in front of you. problem is, input.acceleration gives values repeat themselves, sine curve between 0 (flat on table) , 1 (90 degrees table), y , z axis both @ different intervals (like cos/sin sorta pattern). i'm not quite sure how explain better.. i'll list values y , z each 90 degrees, somehow need convert them 0-4 value, or angle in 360 degrees - sort of linear increasing value z rotation.

0 degrees (flat on table) : y = 0, z = -1

90 degrees (facing towards you) : y = -1, z = 0

180 degrees (flat on table face down) : y = 0, z = 1

270 degrees (facing away you) : y = 1, z = 0

update: using equation {((input.acceleration.y * 2) + input.acceleration.z + 1) * 90f} gives angle between 0, , 360 @ full rotation of device, in between 0 , 90 example, gives value of 120 degrees before going down 90 @ first quarter rotation?

update2: found website shows how use gyroscope give angle device rotation (instead of input.acceleration) using code (c#)

void getzrotation () {     quaternion referencerotation = quaternion.identity;     quaternion devicerotation = new quaternion(0.5f, 0.5f, -0.5f, 0.5f) * input.gyro.attitude * new quaternion(0, 0, 1, 0);     quaternion eliminationofxy = quaternion.inverse(         quaternion.fromtorotation(referencerotation * vector3.forward,                                devicerotation * vector3.forward)         );     quaternion rotationz = eliminationofxy * devicerotation;     float roll = rotationz.eulerangles.z;      return roll; } 

i able solve if knew how worked, , how y value instead of z (i tested , gives linear value between 0 , 360 tilting phone left right, need angle forwards-backwards)

http://answers.unity3d.com/questions/434096/lock-rotation-of-gyroscope-controlled-camera-to-fo.html

this more or less guess, maybe try change getzrotation y axis:

void getyrotation () {     quaternion referencerotation = quaternion.identity;     quaternion devicerotation = new quaternion(0.5f, 0.5f, -0.5f, 0.5f) * input.gyro.attitude * new quaternion(0, 1, 0, 0);     quaternion eliminationofxz = quaternion.inverse(         quaternion.fromtorotation(referencerotation * vector3.up,                                devicerotation * vector3.up)         );     quaternion rotationy = eliminationofxz * devicerotation;     float roll = rotationy.eulerangles.y;      return roll; } 

can't test @ moment, not sure if it'll work needed, worth try think.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -