using System.Collections; using System.Collections.Generic; using UnityEngine; public class Cameracont : MonoBehaviour { public float interpVelocity; public float minDistance; public float followDistance; public GameObject target; public Vector3 offset; Vector3 targetPos; // Use this for initialization void Start() { targetPos = transform.position; } // Update is called once per frame void FixedUpdate() { if (target) { Vector3 posNoZ = transform.position; posNoZ.z = target.transform.position.z; Vector3 targetDirection = (target.transform.position - posNoZ); interpVelocity = targetDirection.magnitude * 5f; targetPos = transform.position + (targetDirection.normalized * interpVelocity * Time.deltaTime); transform.position = Vector3.Lerp(transform.position, targetPos + offset, 0.25f); } } }
ここの処理にMathf.Clampを使い、カメラのy座標の最小値、最大値を取り、動きを制御したいと考えています。
public float Min_y; public float Max_y; Mathf.Clamp(,Min_y,Max_y);
このような処理を考えています。
カメラワークの処理の考え方が不十分なので、詳しい方がいれば教えていただきたいです。
teratailの中だけでも「unity カメラ 範囲」と検索すれば類似質問がたくさん出て来るのですが、何が分からないのでしょうか。こちらも参照してください→https://teratail.com/help/avoid-asking