2016-04-19 14 views
0

私は現在、これは私のことができます。1.回転オブジェクトは、中回転を停止さ/境界

protected void RotationBounds(){ 
bRotateDown = true; 
bRotateUp = true; 
if (_CannonTube.transform.rotation.eulerAngles.z >= 90) 
    bRotateUp = false; 
if (_CannonTube.transform.rotation.eulerAngles.z <= 1) 
    bRotateDown = false; 
} 

下90度を超えないように条件を別のオブジェクトの周りにオブジェクトを回転させると設定するには、次のロジックを使用する限界を破ります条件が当てられたときの方向。

protected void RotateCannonMouse(){ 
if (Input.GetKey ("mouse 0")) { 
     if (Input.GetAxis ("Mouse Y") > 0 && bRotateUp == true && bRotateDown == true 
     || Input.GetAxis ("Mouse Y") > 0 && bRotateUp == false && bRotateDown == true) { 
        transform.RotateAround (_SphereBase.position, -transform.forward, 
        Input.GetAxis ("Mouse Y") * 15); 
      } 
     if (Input.GetAxis ("Mouse Y") < 0 && bRotateUp == true && bRotateDown == true 
     || Input.GetAxis ("Mouse Y") < 0 && bRotateUp == true && bRotateDown == false) { 
        transform.RotateAround (_SphereBase.position, -transform.forward, 
         Input.GetAxis ("Mouse Y") * 15); 
     } 
} 

次のような関数が、更新メソッドで呼び出されます。

void Update() { 
    RotateCannonMouse(); 
    RotationBounds(); 
    } 

私の質問/問題は、私が遅い/中速でオブジェクトを回転移動させる場合の条件がヒットし、それは私が期待してないことです。オブジェクトを速く回転させると、条件を突破して回転を乱します。誰かがこの問題を前にしていたのですか?私はおそらくupdateメソッドが十分に速く反復していないか、オブジェクトをすばやく回転させて境界の値をスキップしていると思っていましたか?高度な

答えて

1

おかげですべてのデータを収集し、すべての計算とチェックを行い、neccessary場合にのみ、最終的に回転させます。あなたはそれをやや後方に行っています。最初に回転させてから混乱をきれいにしようとします。あなたは確かにそれを動作させることができますが、その理由や利益のための最も難しい方法です。

Input.GetAxis("Mouse Y")の戻り値を保存して、計算された(または格納されている)現在のローテーションに追加し、その範囲内にあるかどうかを確認し(またはクランプして)、最後に、あなたは回転します。

は(も、あなたがブールで==行う必要がいけない、すでにその真または偽 - >if(abool == true)if(abool)if(abool == false)と同じであるif(!abool)と同じであることが間違っないOFC、それだけになります。それ)読みにくい

1

これは、我々が

//If mouse has been clicked 
    if (Input.GetKey ("mouse 0")) { 

     //Get the angle the mouse wants to move by 
     float mouseY = Input.GetAxis ("Mouse Y") * 5; 

     //If the angle is not 0 then we see how much it can move by 
     if (mouseY != 0) { 

      //Get the current angle of the cannon 
      float currentAngle = _CannonTube.transform.rotation.eulerAngles.z; 

      //Work out the new angle that the cannon will go to 
      float calcAngle = 0.0f; 

      if (mouseY < 0) { 
       calcAngle = currentAngle - mouseY; 
      } else { 
       calcAngle = currentAngle - mouseY; 
      } 

      //Clamp calcAngle between 5 and 85 
      var newAngle = Mathf.Clamp (calcAngle, 5, 85); 

      //calcualte the angle that we are allowed to move by. 
      //for example if current angle is 85 and new angle is 85 from the clamp then we move 0 degrees 
      var rotateAngle = currentAngle - newAngle; 

      //rotate the cannon 
      transform.RotateAround (_SphereBase.position, -transform.forward, rotateAngle); 
     } 
    } 
+0

を見つけた解決策は今、これはそれdoesntの多くより読みに見えるのですか?あなたはそれが真実か間違っていても同じことをしません。チェックを外して計算を終了してください。実際に計算された値でcalcAngleをすぐに初期化することができます... – yes

関連する問題