Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取附近攻击的数据以避免攻击?_C#_Unity3d_Artificial Intelligence - Fatal编程技术网

C# 如何获取附近攻击的数据以避免攻击?

C# 如何获取附近攻击的数据以避免攻击?,c#,unity3d,artificial-intelligence,C#,Unity3d,Artificial Intelligence,我希望人工智能能够避免攻击,但不知道如何获取数据。我制作了一个警告系统,当警告框和角色发生碰撞时会注意AI。你们可以通过看下面的图片来理解它 在攻击开始之前部署警告。这是警告类的相关代码 private void OnTriggerEnter(Collider other) { CharacterInteractor enemy = other.GetComponent<CharacterInteractor>(); CharacterInteractor atke

我希望人工智能能够避免攻击,但不知道如何获取数据。我制作了一个警告系统,当警告框和角色发生碰撞时会注意AI。你们可以通过看下面的图片来理解它

在攻击开始之前部署警告。这是警告类的相关代码

private void OnTriggerEnter(Collider other)
{
    CharacterInteractor enemy = other.GetComponent<CharacterInteractor>();
    CharacterInteractor atker = attacker.GetComponent<CharacterInteractor>();

    if (enemy != null)
        // attacker and warned characters are different team
        if (attacker == null || enemy.team != atker.team)   
            enemy.Warn(this); 
}
private void OnTriggerExit(Collider other)
{
    CharacterInteractor enemy = other.GetComponent<CharacterInteractor>();
    CharacterInteractor atker = attacker.GetComponent<CharacterInteractor>();

    if (enemy != null)
        if (attacker == null || enemy.team != atker.team)   // 상대가 적일 때
            enemy.WarnOff(this);
}
专用无效对撞机(对撞机其他)
{
CharacterInteractor=other.GetComponent();
CharacterInteractor atker=攻击者.GetComponent();
如果(敌人!=null)
//攻击者和被警告的角色是不同的团队
如果(攻击者==null | |敌方.team!=atker.team)
敌人。警告(这个);
}
私有无效OnTriggerExit(碰撞器其他)
{
CharacterInteractor=other.GetComponent();
CharacterInteractor atker=攻击者.GetComponent();
如果(敌人!=null)
如果(攻击者==null | |敌方.team!=atker.team)//상대가 적일 때
敌人。警告(这个);
}
但现在只知道什么才是危险是不够的。为了找出最佳避免方向,AI还需要其他警告的数据。所以我想到了两种风格,但都有问题

瓷砖系统

平铺系统在角色周围使用多个碰撞器来查找相关警告。在瓷砖之间放置安全位置是不好的

雷达系统

雷达系统对多半径使用SphereCast()。我只能知道警报有多近,警报的中心在哪里,无法得到避免的方向。(也许我现在不知道)


我不知道如何解决这些问题。有什么好的方法或例子来解决这个问题吗?

我和朋友讨论了这个问题,得到了比我要求的更好的想法

改善

  • 瓷砖系统,但使用更小、更多的瓷砖
  • 降低成本

  • 使用5m Sphere Cast查找警告。如果发现警告,请部署磁贴系统矩阵

  • 制作更小的盒子可以解决你的问题。我不确定你是否可以签署你自己的答案作为解决方案,但如果你可以,你应该。