AI行为
来源:互联网 发布:淘宝系统供应商 编辑:程序博客网 时间:2024/04/30 06:11
下面的这个是雷达函数,用来检测周围是不是有队友存在
using UnityEngine;using System.Collections;using System.Collections.Generic;public class Radar : MonoBehaviour { private Collider[] colliders; private float timer = 0; public List<GameObject> neighbors; public float checkInterval = 0.3f; public float detectRadius; public LayerMask layersChecked ; void Start () { neighbors = new List<GameObject>(); } void Update () { timer += Time.deltaTime; //ticked if (timer > checkInterval) { neighbors.Clear(); //检测一定范围内的碰撞体 colliders = Physics.OverlapSphere(transform.position, detectRadius, layersChecked); for (int i=0; i < colliders.Length; i++) { neighbors.Add(colliders[i].gameObject); } timer = 0; } }}
队友检测存在了,好啦,那么开始进行排开 围圈战斗,而不是堆积在一起
using UnityEngine;using System.Collections;[RequireComponent(typeof(Radar))]public class SteeringForSeparation : Steering { public float comfortDistance = 1; public float multiplierInsideComfortDistance = 2; private Transform mTran; void Start () { mTran = this.transform; } void Update() { mTran.position += Force(); } public override Vector3 Force() { Vector3 steeringForce = new Vector3(0,0,0); foreach (GameObject s in GetComponent<Radar>().neighbors) { if ((s!=null)&&(s != this.gameObject)) { Vector3 toNeighbor = transform.position - s.transform.position; float length = toNeighbor.magnitude; steeringForce += toNeighbor.normalized / 20; if (length < comfortDistance) { steeringForce *= multiplierInsideComfortDistance; } steeringForce.y = 0; } } return steeringForce; }}
以后再更新排队,聚集等团体AI行动,弄得AI就跟星际和DOTA似得
0 0
- AI行为
- AI行为的优先级
- AI 行为树框架
- 游戏AI 行为树
- Unity AI 行为树
- UE4 AI行为树简记
- Unity-群组行为AI
- Unity AI 群组行为
- AI巡逻,运用行为树
- [游戏AI]实现掩蔽行为的策略
- [AI-Steering编程]二.寻找行为
- [AI-Steering编程]四.到达行为
- [AI-Steering编程]五.追捕行为
- [AI-Steering编程]六.躲避行为
- [AI-Steering编程]七.漫游行为
- [AI-Steering编程]十.群落行为
- 行为树游戏AI PPT(珠三角沙龙)
- 行为型AI:寻找迷宫出口
- android打包release导致java.lang.NoClassDefFoundError
- 【Gerrit】添加git工程到gerrit服务器
- 卸载LoadRunner
- 自定义控件---类似添加邮件收件人效果
- iOS7自带扫描二维码、条形码功能实现
- AI行为
- lr中错误解决方法(收集)
- JavaScript解析xml文件的省市联动
- iOS应用调用系统打电话、发短信和发邮件功能
- 大规模图搜索和实时计算在阿里反作弊系统中的应用
- centos环境下使用percona-xtrabackup对mysql5.6数据库innodb和myisam进行快速备份及恢复
- IdWorker 2
- caffe源码 之 池化层
- 学习“HTML5 移动webapp阅读器”心得