脑瘫,要先在update里调用计算函数。
private void Update()
{
CalculateTangent();
Debug.DrawLine(this.transform.position, leftTangent, Color.red);
Debug.DrawLine(this.transform.position, rightTangent, Color.red);
}
未在切点位置:
private void CalculateTangent()
{
Vector3 playerToExplosion = this.transform.position - playerTF.position;
Vector3 playerToExplosionDirection = playerToExplosion.normalized * radius;//乘上半径
Debug.DrawLine(this.transform.position, playerToExplosion, Color.red);
float angel01 = Mathf.Acos(radius / playerToExplosion.magnitude) * Mathf.Rad2Deg;
leftTangent = playerTF.position + Quaternion.Euler(0, -angel01, 0) * playerToExplosionDirection;//四元数.欧拉角(x,x,x)用法
rightTangent = playerTF.position + Quaternion.Euler(0, angel01, 0) * playerToExplosionDirection;
}