Unity人工智能学习—确定性AI算法之随机运动
发布日期:2021-06-29 04:53:50
浏览次数:2
分类:技术文章
本文共 2126 字,大约阅读时间需要 7 分钟。
以下所写内容都是平时学习人工智能的时候有意的将它们转换成Unity的实现版本。所谓确定性算法是一些预先确定或者预先编程的操作,比如《星球大战》游戏中的小行星的AI都是非常简单的,都是以随机速率将其沿着随机的方向发射出去,这是一种最简单的智能,不过它们的智能都是相当确定和可预知的。
而确定性AI算法里面,随机运动又是最简单的,如图
我设置了移动随机和停留随机时间,这样看上去才更加真实。
using UnityEngine;using System.Collections;public class AIRandMove : MonoBehaviour{ float stopTime; float moveTime; float vel_x, vel_y, vel_z;//速度 ////// 最大、最小飞行界限 /// float maxPos_x = 500; float maxPos_y = 300; float minPos_x = -500; float minPos_y = -300; int curr_frame; int total_frame; float timeCounter1; float timeCounter2; // int max_Flys = 128; // Use this for initialization void Start() { Change(); } // Update is called once per frame void Update() { timeCounter1 += Time.deltaTime; if (timeCounter1 < moveTime) { transform.Translate(vel_x, vel_y, 0, Space.Self); } else { timeCounter2 += Time.deltaTime; if (timeCounter2 > stopTime) { Change(); timeCounter1 = 0; timeCounter2 = 0; } } Check(); } void Change() { stopTime = Random.Range(1, 5); moveTime = Random.Range(1, 20); vel_x = Random.Range(1, 10); vel_y = Random.Range(1, 10); } void Check() { //如果到达预设的界限位置值,调换速度方向并让它当前的坐标位置等于这个临界边的位置值 if (transform.localPosition.x > maxPos_x) { vel_x = -vel_x; transform.localPosition = new Vector3(maxPos_x, transform.localPosition.y, 0); } if (transform.localPosition.x < minPos_x) { vel_x = -vel_x; transform.localPosition = new Vector3(minPos_x, transform.localPosition.y, 0); } if (transform.localPosition.y > maxPos_y) { vel_y = -vel_y; transform.localPosition = new Vector3(transform.localPosition.x, maxPos_y, 0); } if (transform.localPosition.y < minPos_y) { vel_y = -vel_y; transform.localPosition = new Vector3(transform.localPosition.x, minPos_y, 0); } }}
转载地址:https://blog.csdn.net/zhangxiao13627093203/article/details/47444623 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月16日 17时30分47秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
记一次django项目的部署
2019-04-29
测试项目调研
2019-04-29
接手软件测试新项目的流程
2019-04-29
jmeter-性能测试2-脚本录制开发
2019-04-29
jmeter-性能测试3-参数化
2019-04-29
期货基础知识
2019-04-29
期权基础
2019-04-29
jmeter-性能测试6-性能基础扫盲
2019-04-29
pytest+allure生成测试报告
2019-04-29
接口测试用例
2019-04-29
vnc安装配置
2019-04-29
Allure 测试报告:allure.title 去掉后方的参数化显示
2019-04-29
appium起源-环境配置
2019-04-29
appium初识-firstdemo
2019-04-29
allure报告的定制化
2019-04-29
怎样给excel添加一行数据
2019-04-29
怎样彻底帮妹子解决weditor的安装的问题
2019-04-29
干货|一次完整的性能测试,测试人员需要做什么?
2019-04-29
全栈性能测试修炼宝典
2019-04-29
jmeter-性能测试9-测试执行
2019-04-29