Unity的C#编程教程_11_Quaternion Slerp(四元数球面线性插值)
- 2020 年 7 月 21 日
- AI
- C/C++/C#
- 代表线性插值 Linear Interpolation,但是球状的
- 不是和目标方向点直接连接(联动),而是平滑地移动到目标方向
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AimSlerp : MonoBehaviour
{
[SerializeField]
private Transform _cube;
void Start()
{
}
void Update()
{
Vector3 directionToFace = _cube.position - transform.position;
Debug.DrawRay(transform.position, directionToFace, Color.green);
Quaternion targetRotation = Quaternion.LookRotation(directionToFace);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime);
}
}