private void Update() { blueAxis = cameraTrans.forward; redAxis = cameraTrans.right; blueAxis.y = 0; redAxis.y = 0; if (isLocked) { return; } inputAxis = m_AndroidInput.GradientAxis; gravityOffset = Input.acceleration - standardGravityAxis; //P.PUBLIC.debugText2.text = gravityOffset.ToString(); //重力在本地坐标系的向量为standard,当坐标系旋转后,变成Input.acceleration //坐标系所有点乘以旋转矩阵mat,Input.acceleration乘以mat的逆矩阵等于standard //Matrix4x4 rotateMatrix = STL.Geometry.Math.CalcRotateMatrix(Input.acceleration, standardGravityAxis); Vector3 rotateAxis = Vector3.Cross(Input.acceleration, standardGravityAxis); float angle = Vector3.Angle(Input.acceleration, standardGravityAxis); //m_rigidbody.MoveRotation transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(angle, rotateAxis), 0.05f); m_Actor.GoForward(); dir = inputAxis.x * redAxis + inputAxis.y * blueAxis; //m_Actor.Fly(dir); m_Actor.Move(dir); Debug.Log(gravityOffset); if (_AndroidInput.wantReset) { ResetGravityController(); } }