【发布时间】:2021-12-13 23:59:29
【问题描述】:
我已经完成了这个程序,但是当我移动我的游戏对象(第二个)时,y 中的第一个游戏对象的旋转开始随机从 90 到 -90。
public GameObject target;
public float rotSpeed;
void Update(){
Vector3 dir = target.position - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, angle));
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotSpeed * Time.deltaTime);
}
【问题讨论】:
-
Quaternion.AngleAxis试试这个 api 吗?
标签: c# unity3d rotation gameobject