2017-03-26 19 views
0

私はあなたの実際の身体を見ることができる統一されたFPPモードを作ろうとしています。私はモデルを作り、すべてを組み立てました。私の頭はカメラに回転しますが、私はプレーヤーが自分の体の周りを回転できるようにしたくありません。私はすでにx軸に回転をクランプしていますが、y軸を中心にクランプに問題があります。ユニティヘッドY軸回転クランプ

void Update() { 
currentBodyRotation = body.GetComponent<Transform>().rotation.eulerAngles.y; 

    yaw += Input.GetAxis ("Mouse X") * mouseSensitivity; 


    yawMin = currentBodyRotation - 90f; 
    yawMax = currentBodyRotation + 90f; 

    yaw = Mathf.Clamp (yaw, yawMin, yawMax); 



    pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity; 
    pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y); 


    currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime); 
    transform.rotation = Quaternion.Euler (currentRotation); 

} 

0度と360度の角度では回転に限界があると思います。ボディコードが360度になるまで私のコードは完全に機能します。それが起こると、私のカメラは急に動き、目に見えない壁からそれが来た側に戻ってくるだけです。

+0

[本](http://stackoverflow.com/a/37089547/3785314)カメラの制限のために試してみてください。それはうまくいくはずです。 – Programmer

+0

動作しません。 transform.localEulerAnglesは私のカメラとアニメーションをねじ込みます。 編集:私はそれを修正しましたが、まだ動作しません。マウス入力の一部が止まった。 –

+0

あなたは角度制限付きでカメラを動かしていると思っています。そのコードはFPSカメラ用であり、アニメーションなしでカメラに接続する必要があります。 – Programmer

答えて

0

私はそれを理解した。誰かが似たような問題を抱えている場合は、コードがあります。

void Update() { 

    yaw += Input.GetAxis ("Mouse Y") * mouseHorizontalSensitivity; 


    yaw = Mathf.Clamp (yaw, -30f, 80f); // It's pitch but my code works weird 



    pitch -= Input.GetAxis ("Mouse X") * mouseVerticalSensitivity; 
    pitch = Mathf.Clamp (pitch, -90f, 90f); // it's yaw 


    currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (-pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime); 
    transform.localEulerAngles = currentRotation; 

// my mouse input wouldn't go down which caused the model to rotate indeffinitely so i added smoothing to 0 for rotating around Y axis which here is labeled as pitch 
    if (!Input.GetKey (KeyCode.LeftAlt)) 
     pitch = Mathf.SmoothDamp(pitch, 0f, ref rotationSmoothVelocity2, rotationSmoothTime); 

}

関連する問題