Skip to content

Instantly share code, notes, and snippets.

@Tunied
Created September 16, 2022 05:01
Show Gist options
  • Save Tunied/ed397ce137d248841df7662118c1c33c to your computer and use it in GitHub Desktop.
Save Tunied/ed397ce137d248841df7662118c1c33c to your computer and use it in GitHub Desktop.
相机绕着某个目标移动
private void OrbitCamera()
{
//orbit camera - 让相机在一个固定水平高度上绕着物体旋转.用于第三人称视角时候人物跟踪
//lookAngle为定义的视角new Vector(45,30,0) 表示离地角度是45°,水平旋转角度是30°
//因为是正交相机,所以相机距离物体远近无异议,所以才用常量20f作为距离
var lookQuaternion = Quaternion.Euler(lookAngle);
var lookDirection = lookQuaternion * Vector3.forward;
var lookPosition = transform.position - lookDirection * 20f;
Camera.SetPositionAndRotation(lookPosition, lookQuaternion);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment