私はすべての方向でポイント(0,0,0)を回りたいカメラを持っていますが、ポイントの上または下にあまりにも遠くに行くことはできません。私は、この質問が左右の方向について前に答えたが、直前のものについては答えなかった。どのように制限する(クランプ)Y軸回転のための回転。回転ユニティ
私はこれらの2つの質問(基本的に同じことを言う)からコードを垂直方向に動作させようとしましたが、回転に沿ったいくつかの点でバグがあります。
First Question、Second Question
そしてこれは、私はそれを変換しようとした方法である:
//how much we want to rotate by this frame
float rotX = Input.GetAxis("Mouse X") * rotSpeed;
float rotY = Input.GetAxis("Mouse Y") * rotSpeed; //(before clamping)
//find current direction
Vector3 currentDirection = transform.position - Vector3.zero;
//find current angle between basis for clamp & where we are now
float angle = Vector3.Angle(Vector3.forward, currentDirection);
//finds out if it's up or down
if (Vector3.Cross(Vector3.forward, currentDirection).x < 0) angle = -angle;
//find out how much you can move without violating limits
float newAngle = Mathf.Clamp(angle + rotY, yMinLimit, yMaxLimit);
//grabs how much you are allowed to move the angle from the current angle
rotY = newAngle - angle;
//spinning the garden
transform.RotateAround(Vector3.zero, Vector3.up, rotX);
transform.RotateAround(Vector3.zero, transform.TransformDirection(Vector3.right), -rotY); //vertical rotation
誰もがY軸のため、この作品を作るための正しい方法、またはクランプする別の方法を知っている場合垂直回転、私はそれを聞くために興奮してスーパーだろう!タイ!
申し訳ありませんが、返信に数日かかりました。最後にそれをテストする時間があり、それは完全に動作します!私の答えの検索で、Unity Answersの別の記事を同じ質問で見つけましたが、この投稿へのリンクを渡すと気になりますか? –
私はまったく気にしません。実際、私はこの答えがより多くの人々を助けることを知ってうれしいです。 :-)(あなたのコメントへの遅れた答えには申し訳ありません) – Fenixrw