当前位置:网站首页>Find points without obstacles on 3D map
Find points without obstacles on 3D map
2022-04-22 07:50:00 【Dream back to Datang knock code】
// The last detected location without obstacles
Vector3 strkeFlyPos;
// The rotation angle of the vector each time
public float rotationAngle = 180;
// The direction of the vector , Express x The positive direction of the axis
Vector3 dirTarget = new Vector3(5, 0, 0);
// The length of the vector
float _v3Lenght = 5;
// Target location
Vector3 _target;
/// <summary>
/// Find a point that has no obstacles on the map with itself as the origin
/// </summary>
/// <param name="_angle"></param>
public void StrkeFly(float _angle)
{
for (int i = 0; i < 360 / _angle; i++)
{
// Temporarily record the position of the current point found // Let yourself add a radius ( This radius is just a left side with 5 The direction vector of ), Let this vector rotate , Get a circular point around yourself
Vector3 tempPos = transform.position + Quaternion.AngleAxis(_angle * i, transform.up) * dirTarget.normalized * _v3Lenght;
// A ray is emitted from the camera to detect whether the point is an obstacle
Ray ray = new Ray(Camera.main.transform.position, tempPos - Camera.main.transform.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
// If not, let the enemy be hit and fly to this point
if (hit.transform.tag == "ground")
{
_target = hit.point;
// Method of calling base note after finding target position
StartCoroutine("FlyTaget");
return;
}
}
}
// After a week of searching , Can't find , Then reduce the rotation angle of the vector , And call itself
if (_angle > 1)
{
StrkeFly(_angle / 2);
return;
}
// When the angle is less than 1 I haven't found it yet , Then reduce the length of the vector and keep looking
if (_angle < 1 && _v3Lenght > 1)
{
_v3Lenght -= 1;
StrkeFly(_angle);
return;
}
}
版权声明
本文为[Dream back to Datang knock code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621526957.html
边栏推荐
猜你喜欢
随机推荐
@ transactional transaction propagation in the same class
第六章第二节 Map和结构体
Mysql 配置查询
List 交集、并集、去重、抽取、修改属性等常用操作
unity面試題
Crawler 51job
7-2 Tushare
if语句格式流程
从零学C语言 【一】基本概念
7-1金融介绍
Unity~脚本的生命周期
寻找3d地图上没有障碍物的点
“可视化程序设计”试卷
数据库-Mysql--Navicat 导入sql出现错误 1067 - Invalid default value for ‘payDate‘
C-11 Problem I: 找气球
Opportunity interview questions
Distinction
跳转语句的三种
unity小游戏及相关面试题
关于SM2加密验签的操作









