Unity 移动端实现pad 端acceleration 控制移动、旋转

来源:互联网 发布:维棠flv mac 编辑:程序博客网 时间:2024/06/05 00:29

1、在Character Controllers中拖入 预制体First Person Controller;

2、将 FPSInputController 另存为 FPSctl ,并做一下修改:

(1)增加变量:

 private float rotationY;

  (2)注释掉   var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

加入:

  var v = new Vector3(Input.acceleration.x, Input.acceleration.y,( 1+(Input.acceleration.z))).normalized;
        labeltext.text = ("v.x " + (v.x).ToString() + "rotationY" + rotationY);
        if (v.z > 0)
        {
             directionVector = new Vector3(v.x, 0, 1-v.z);
        
        }
      
        else
        {
            directionVector = new Vector3(0, 0,0);
           
        }

(3)在 motor.inputMoveDirection = transform.rotation * directionVector;前一行

加入:

    rotationY = rotationY + v.x;
            // Apply the direction to the CharacterMotor
            this.transform.eulerAngles = new Vector3(0, rotationY, 0);


发布在IOS设备上时:



即可测试,运行。


0 0