public Camera camera;
public tranform tarPos;
public bool cameraMove=false;
private Vector3 velocity = Vector3.zero;
public Button btn;
void Start()
{
btn.onClick.AddListener(delegate
{
cameraMove=true;
});
}
void Update()
{
if (camerMove)
{
camera.position =
Vector3.SmoothDamp (camera.position, tarPos.position, ref velocity, 2f);
camera.rotation = Quaternion.RotateTowards( camera.rotation, tarPos.rotation,Time.deltaTime*20);
}
}
Unity中使用Vector3.SmoothDamp(平滑阻尼)方法进行跟随移动,可以使跟随看起来很平滑,而不显得突兀,最典型的示例就是相机平滑跟随角色移动。文章来源:https://www.toymoban.com/news/detail-508206.html
SmoothDamp (current : Vector3, target : Vector3, ref currentVelocity : Vector3, smoothTime )
文章来源地址https://www.toymoban.com/news/detail-508206.html
到了这里,关于unity摄像机平滑移动旋转的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!