Unity GameAI-(6)Obstacle Avoidan
作者:
Levi_Wan | 来源:发表于
2016-12-08 00:08 被阅读79次
动态避障在Unity中的实现
- 首先需要添加一个obstacle(障碍物的layer),这里为第九层

Paste_Image.png
- 接着为我们需要避障的物体添加CollisionAvoidance脚本

Paste_Image.png
- 脚本代码
- 这里使用恒力来实现避障,而不是距离越近力越大的方式

Paste_Image.png
- 通过transform.position 和速度方向上探针的长度来得到ahead

Paste_Image.png
- 将Seek AI 封装成一个方法,并且指定操控力的y为0,避免脱离平面

Paste_Image.png

Paste_Image.png

1.gif
- 第二种避障,直接找出与物体运动速度垂直的向量来作为操控力使物体避障。

Paste_Image.png

2.gif
本文标题:Unity GameAI-(6)Obstacle Avoidan
本文链接:https://www.haomeiwen.com/subject/gjmjmttx.html
网友评论