zoukankan      html  css  js  c++  java
  • Unity3D编程学习 小知识_扇形攻击_2018Oct

    当需要判断一物体是否位于当前物体前方扇形范围内时  运用距离差和角度差实现判断

    //扇形攻击 实现类型_1
    public bool UmbrellaAttact( Transform attacker ,Transform attacked ,float angle, float radius)
    {

       Vector3 deltaA = attacked.position - attacker.position;

       float tmpAngle = Mathf.Acos(Vector3.Dot(deltaA.normalized, attacker.forward)) * Mathf.Rad2Deg;

       if (tmpAngle < angle * 0.5f && deltaA.magnitude < radius)
       {
         return true;
       }
       return false;
    }

    //扇形攻击 实现类型_2
    //距离差为半径 角度差为扇形角度的一半
    Transform Target;

    float _Dis = Vector3.Distance(Target.position, transform.position);
    float _Angle = Vector3.Angle(Target.position-transform.position,transform.forward)

    if (_Angle < x && _Dis < y)
    {
       Debug.logFormat("在范围内");
    }

  • 相关阅读:
    MySQL学习笔记:coalesce
    Oracle学习笔记:decode函数
    MySQL学习笔记:like和regexp的区别
    状态图
    构件图和部署图
    java基础知识(一)
    包图
    活动图
    协作图
    序列图
  • 原文地址:https://www.cnblogs.com/RainPaint/p/9829505.html
Copyright © 2011-2022 走看看