Unity人工智能学习—确定性AI算法之追踪算法一
转自http://blog.csdn.net/zhangxiao13627093203/article/details/47451063
尽管随机运动可能完全不可预知,它还是相当无趣的,因为它完全是以相同的方式工作——完全随机。下面要学习到的算法是根据具体环境作出不同响应的处理。作为例子,这里选择了追踪算法。追踪AI考虑到跟踪目标的位置,然后改变AI对象的轨道好让它移向被追踪的对象。
追踪可以是将方向矢量直接指向目标,或者采用跟真实的模型,使得物体像导弹那样行动。
本文将的就是第一种,直接矢量追踪,效果如下图所示:
通过键盘方向键控制幽灵,然后蚊子会追踪幽灵,在这里我做了一些界面处理,当蚊子或者幽灵运动超过了屏幕范围的时候让它们出现在屏幕的另一边而不是消失在屏幕上
代码如下:
using UnityEngine;
using System.Collections;
using UnityEngine.UI; public class AITrack : MonoBehaviour {
public Image target;
public float moveSpeed;//追踪目标移动速度
public float targetSpeed;//追踪速度
public float target_x;//追踪移动的单位量
public float target_y;
// Use this for initialization
void Start () { }
// Update is called once per frame
void Update () {
MoveTarget();
Track_AI();
}
void Track_AI()
{
//x方向的追踪
if(target.transform.position.x>this.transform.position.x)
{
this.transform.position += new Vector3(target_x, 0, 0)*targetSpeed;
}
else if(target.transform.position.x<this.transform.position.x)
{
this.transform.position -= new Vector3(target_x, 0, 0)*targetSpeed;
}
//y方向的追踪
if(target.transform.position.y>this.transform.position.y)
{
this.transform.position += new Vector3(0, target_y, 0)*targetSpeed;
}
else if(target.transform.position.y<this.transform.position.y)
{
this.transform.position -= new Vector3(0, target_y, 0)*targetSpeed;
}
//检测是否超出了边界
if(this.transform.position.x>=Screen.width)
{
this.transform.position = new Vector3(-this.GetComponent<Image>().rectTransform.lossyScale.x, 0, 0);
}
else if(this.transform.position.x<-this.GetComponent<Image>().rectTransform.lossyScale.x)
{
this.transform.position = new Vector3(Screen.width, this.transform.position.y, 0);
}
if(this.transform.position.y>=Screen.height)
{
this.transform.position = new Vector3(this.transform.position.x,-this.GetComponent<Image>().rectTransform.lossyScale.y, 0);
}
else if(this.transform.position.y<-this.GetComponent<Image>().rectTransform.lossyScale.y)
{
this.transform.position = new Vector3(this.transform.position.x, Screen.height, 0);
}
}
void MoveTarget()
{
float x = Input.GetAxis("Horizontal")*100;
float y = Input.GetAxis("Vertical")*100; target.transform.Translate(x*Time.deltaTime*moveSpeed,y*Time.deltaTime*moveSpeed,0);
//如果超出屏幕范围则让它出现在另一面
if (target.transform.position.x >= Screen.width)
{
//使用了Image的target.rectTransform.lossyScale.x来表示显示的图片宽度
target.transform.position = new Vector3(-target.rectTransform.lossyScale.x, target.transform.position.y, 0);
}
else if(target.transform.position.x<-target.rectTransform.lossyScale.x)
{
target.transform.position = new Vector3(Screen.width, target.transform.position.y, 0);
}
if(target.transform.position.y>=Screen.height)
{
target.transform.position = new Vector3(target.transform.position.x, -target.rectTransform.lossyScale.y, 0);
}
else if(target.transform.position.y<-target.rectTransform.lossyScale.y)
{
target.transform.position = new Vector3(target.transform.position.x, Screen.height, 0);
}
}
}
Unity人工智能学习—确定性AI算法之追踪算法一的更多相关文章
- Unity人工智能学习—确定性AI算法之追踪算法二
转自:http://blog.csdn.net/zhangxiao13627093203/article/details/47658673 上一篇讲到了追踪算法的比较简单的形式,看上去比较假,因为AI ...
- AI 经典书单 | 人工智能学习该读哪些书
转载 2018年01月16日 00:00:00 人工智能相关岗位中,涉及到的内容包含: 算法.深度学习.机器学习.自然语言处理.数据结构.Tensorflow.Python .数据挖掘.搜索开发. ...
- 游戏人工智能 读书笔记 (四) AI算法简介——Ad-Hoc 行为编程
本文内容包含以下章节: Chapter 2 AI Methods Chapter 2.1 General Notes 本书英文版: Artificial Intelligence and Games ...
- 【中国象棋人机对战】引入了AI算法,学习低代码和高代码如何混编并互相调用
以低代码和高代码(原生JS代码)混编的方式引入了AI算法,学习如何使用表达式调用原生代码的.整个过程在众触低代码应用平台进行,适合高阶学员. AI智能级别演示 AI算法分三个等级,体现出来的智能水平不 ...
- 【AI】微软人工智能学习笔记(一)
数据分析平台 01|数据平台概况图示 上面图中所示就是微软人工智能数据平台的相关的技术. 02.1| Cortana Intelligence Suite 从上面图中可以看到, 其中有一个Cortan ...
- AI人工智能学习数据集
AI人工智能学习数据集,列表如下. 商务合作,科技咨询,版权转让:向日葵,135—4855__4328,xiexiaokui#qq.com boston_house_prices.csvbreast_ ...
- 聊聊找AI算法岗工作
https://blog.csdn.net/weixin_42137700/article/details/81628028 首先,本文不是为了增加大家的焦虑感,而是站在一名学生的角度聊聊找AI算法岗 ...
- 2017人工智能元年,AI在喧嚣和质疑中一路走来
前百度首席科学家吴恩达说:就像100年前的电力.20年前的互联网一样,AI也会改变每一个产业! 有人说,现在就像1995年,那一年,第一家互联网公司--网景上市,一天之内大涨208%,互联网正式登上历 ...
- 曼孚科技:AI算法领域常用的39个术语(下)
算法是人工智能(AI)核心领域之一. 本文整理了算法领域常用的39个术语,希望可以帮助大家更好地理解这门学科. 本文为下半部分,上半部分见本账号上一篇文章. 19.迁移学习(Transfer Lear ...
随机推荐
- Dotfuscator注册码和XenoCode注册码
.net加密工具注册码:Dotfuscator注册码如下: Your serial number is 14705 Your Confirmation Numb ...
- linux 之 popen函数
描述 popen() 函数 用 创建管道 的 方式启动一个 进程, 并调用 shell. 因为 管道是被定义成单向的, 所以 type 参数 只能定义成 只读或者 只写, 不能是 两者同时, 结果流也 ...
- Dynamicaly Typed(动态定型), Objective-C Runtime Programming
Objective-C跟C最大的差别,应该是动态定型(dynamicaly typed),支持在运行时动态类型决议(dynamic typing),动态绑定(dynamic binding)以及动态装 ...
- Leetcode::Pathsum & Pathsum II
Pathsum Description: Given a binary tree and a sum, determine if the tree has a root-to-leaf path su ...
- 企业架构研究总结(25)——TOGAF架构开发方法(ADM)之迁移规划阶段
1.8 迁移规划(Migration Planning) 企业架构开发方法各阶段——迁移规划 1.8.1 目标 本阶段的目标是: 确保实施和迁移规划与企业中各种管理框架相协调. 通过对每个进行中的成本 ...
- SQL 语句中的union操作符
前端时间,用到了union操作符,周末有时间总结下,w3c手册内容如下: SQL UNION操作符 UNION操作符用于合并两个或多个select语句的结果集. 注意:UNION内部select语句必 ...
- 对象池化技术 org.apache.commons.pool
恰当地使用对象池化技术,可以有效地减少对象生成和初始化时的消耗,提高系统的运行效率.Jakarta Commons Pool组件提供了一整套用于实现对象池化的框架,以及若干种各具特色的对象池实现,可以 ...
- linux serial 登录 cubieboard
折腾半天linux下的putty,最后搞得实在没办法,放弃putty改用minicom 1. 先安装minicom sudo apt-get install minicom 2.配置com minic ...
- Mac下chrome的webapp hostadmin 快速切换host
首先是安装 app ,https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg ...
- 定时器Timer不定时
订餐系统之定时器Timer不定时 经过几天漫长的问题分析.处理.测试.验证,定时器Timer终于定时了,于是开始了这篇文章,希望对还在纠结于“定时器Timer不定时”的同学有所帮助,现在的方案,在系统 ...