博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NavMesh动态碰撞
阅读量:7127 次
发布时间:2019-06-28

本文共 2115 字,大约阅读时间需要 7 分钟。

今天遇到一个问题,就是怎样处理一些动态的障碍物。

NavMesh是能够躲避静态的障碍物。NavMeshObstacle的作用就是动态添加障碍。

可是有个问题,NavMeshObstacle是圆,连椭圆都不行,所以。仅仅好写一个附属脚本。用圆拼成矩形,就能够了。

using UnityEngine;using System.Collections;public class NavMeshObstacleHelper : MonoBehaviour {	//coordinate	public float X = 0f;	public float Y = 0f;	public float Z = 0f;	public float Length = 0f;	public float Width = 0f;	public float Height = 0f;	public float Diameter = 0f;	private int lengthCount = 0;	private float lengthStep = 0f;	private int widthCount = 0;	private float widthStep = 0f;	private GameObject obstacleArray = null;	private GameObject obstacle = null;	void Awake()	{		obstacleArray = new GameObject ();		obstacleArray.name = "NavMeshObstacleArray";		widthCount = (int)(Width / Diameter);			lengthCount = (int) (Length / Diameter);		if (lengthCount > 1)		{			lengthStep = (Length - Diameter * lengthCount) / (lengthCount - 1);		}				if (widthCount > 1)		{			widthStep = (Width - Diameter * widthCount) / (widthCount - 1);		}	}	// Use this for initialization	void Start () {		initObstacleArray ();	}	private void initObstacleArray()	{		Vector3 tempPos = new Vector3 (X, Y, Z);		for (int i = 0; i < lengthCount; i++)		{			for (int j = 0; j < widthCount; j++)			{				obstacle = new GameObject ();				obstacle.transform.position = tempPos;				obstacle.transform.parent = obstacleArray.transform;				obstacle.AddComponent 
(); NavMeshObstacle navMeshObstacle = obstacle.GetComponent
(); if (navMeshObstacle) { obstacle.GetComponent
().radius = Diameter / 2; obstacle.GetComponent
().height = Height; } tempPos = new Vector3 (tempPos.x, tempPos.y, tempPos.z + Diameter + widthStep); } tempPos = new Vector3 (tempPos.x + Diameter + lengthStep, tempPos.y, Z); } obstacleArray.transform.parent = this.transform; obstacleArray.transform.localRotation = Quaternion.identity; obstacleArray.transform.position = this.transform.position; } // Update is called once per frame void Update () { }}
思路来源自http://www.cnblogs.com/sifenkesi/p/4004215.html

能够看一下。效果:

參数设置

你可能感兴趣的文章
tab标签
查看>>
ecshop新增银联企业网银支付方式
查看>>
Angular5学习笔记 - 配置NG-ZORRO(八)
查看>>
使用Netty实现HTTP服务器
查看>>
JAVA开发工具eclipse中@author怎么改
查看>>
存储引擎与锁
查看>>
sqlog连接虚拟机mysql服务
查看>>
出错,网页显示不出内容
查看>>
Spring中的后置处理器BeanPostProcessor讲解
查看>>
《FPGA全程进阶---实战演练》第十四章 蜂鸣器操作
查看>>
浅析firmware完整生存和使用流程 【转】
查看>>
《30天自制操作系统》笔记(01)——hello bitzhuwei’s OS!【转】
查看>>
MMU介绍【转】
查看>>
构造函数
查看>>
HTML 5 History API的”前生今世”
查看>>
电脑高手常用快捷键
查看>>
杨辉三角形
查看>>
css3 flex笔记整理
查看>>
swift 分组tableview 设置分区投或者尾部,隐藏默认间隔高度
查看>>
MySQL案例09:Last_IO_Error: Got fatal error 1236 from master when reading data from binary log
查看>>