统一将精灵旋转到面向量

时间:2019-07-19 14:51:52

标签: c# unity3d

我有一个僵尸gameObject和一个塔形gameObject。 我尝试了很多方法使敌人面对塔内嵌套对象的位置,但没有任何效果。

我已经尝试使用Mathf.Acos无效。 我最接近的就是使用此代码; 但是它仍然稍微掩盖了预期的方向,我还没有找到任何模式。

Vector2 direction = centralTower.transform.position + centralTower.transform.parent.transform.position - gameObject.transform.position;

transform.up = direction;
gameObject.transform.position += transform.up;

我知道第一行看起来很宽,但基本上可以简化为

direction =(TowerPosition + TowerChild(attakcingPoint)Position)-敌人位置

顺便说一句:塔中央变量指的是攻击点

我真的不知道发生了什么,并且我已经研究了好几天了,但没有任何效果。

1 个答案:

答案 0 :(得分:1)

一个similar question提供了答案transform.right = target.position - transform.position;