Unity技能伤害区域判定(矩形,圆,三角形,扇形)
程序员文章站
2022-03-22 14:59:04
欢迎加入Unity业内qq交流群:956187480qq扫描二维码加群源码地址:https://download.csdn.net/download/qq_37310110/10886004一. 判断目标点是否在指定的扇形内 public GameObject target; private float skillDistance = 5; private float skillAngle = 60; // Update is called on......
欢迎加入Unity业内qq交流群:956187480
qq扫描二维码加群
源码地址:https://download.csdn.net/download/qq_37310110/10886004
一. 判断目标点是否在指定的扇形内
public GameObject target;
private float skillDistance = 5;
private float skillAngle = 60;
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(transform.position, target.transform. position);
Vector3 norVec = transform.localPosition+new Vector3(0,0, skillDistance);
Vector3 temVec = target.transform.position - transform.position;
Debug.DrawLine(transform.position, norVec, Color.red);
Debug.DrawLine(transform.position, target.transform.position, Color.green);
if (Input.GetKeyDown(KeyCode.Q))
{
//计算两个向量间的夹角
float angle = Mathf.Acos(Vector3.Dot(norVec.normalized, temVec.normalized)) * Mathf.Rad2Deg;
if (distance <= skillDistance && angle * 2 <= skillAngle)
{
Debug.Log("在扇形范围内");
}
else
{
Debug.Log("不在扇形范围内");
}
}
}
欢迎加入Unity业内qq交流群:956187480
qq扫描二维码加群
本文地址:https://blog.csdn.net/qq_37310110/article/details/110131107
上一篇: vue实现简单计算商品价格
下一篇: python- os模块学习-自用