当前位置:网站首页>Unity_平滑移动

Unity_平滑移动

2022-08-09 19:20:00 不可_收_圾

/*用场景中target物体位置为基准进行偏移后的位置作为位移目标点位置*/
public Transform target;
public float smoothTime = 0.75F;//移动花费的时间,越小速度越快
private Vector3 velocity = Vector3.zero;

void Start()
{
	
}

void Update()
{
	Vector3 targetPosition = target.TransformPoint(new Vector3(0, 0, -10));//在target物体位置基础上把Z轴偏移-10距离的位置点
	transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
	/*velocity为当前速度,此值由函数在每次调用时进行修改*/
}
原网站

版权声明
本文为[不可_收_圾]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_36917144/article/details/126202474