新しいゲームを開始していますが、今プレイヤーは360 *を見ることができますが、プレーヤーが空からどれだけ遠くに(上下に)見上げるかを制限したいと思います。 は、ここに私のコードあなたがこれを行うにはMathf.Clamp
を使用する必要がFPSカメラのy軸を特定の角度に制限します
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
GameObject player;
void Start() {
player = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update() {
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f/smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f/smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
player.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, player.transform.up);
}
}
プレーヤー変数はカメラですか? – Programmer
ええ、Player変数はカメラ – Johnny