This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

创建路由

UNIGINE has a built-in pathfinding system that includes navigation areas, obstacles and functions of the PathRoute class that are used to calculate the optimal routes among obstacles within navigation areas.UNIGINE有一个内置的寻路系统,包括导航区域障碍物PathRoute类的函数,用于计算导航区域内障碍物之间的最佳路线。

警告
3D navigation feature is experimental and not recommended for production use.3D导航功能是实验性的,不建议在最终应用程序中使用。

Via UnigineEditor, you can only add a navigation area (a sector or a mesh) to the scene and place obstacles. The 2D or 3D route that is calculated within the navigation area should be created from the code.通过UnigineEditor,您只能在场景中添加导航区域(扇区或网格)并放置障碍物。 应从代码创建在导航区域内计算的2D或3D路线。

Creating a Route within Navigation Area
在导航区域内创建路线#

To create a route within a navigation area, in which no obstacles are placed, you can use the following:要在不放置障碍物的导航区域内创建路线,可以使用以下方法:

You can affect route calculation via UnigineEditor by adjusting parameters of the navigation sector or mesh.您可以通过UnigineEditor通过调整导航扇区或网格的参数来影响路线计算。

Creating a Route within Navigation Area with Obstacles
在有障碍物的导航区域内创建路线#

Creating the route within a navigation area with obstacles is similar to creating the route within an empty navigation area. Moreover, the route will be recalculated if the obstacle changes its transformation.在具有障碍的导航区域内创建路线类似于在空导航区域内创建路线。 此外,如果障碍物改变其变换,则会重新计算路线。

If the obstacle is connected with a dynamically changing node that should be bypassed, this node should be set as a parent node for the obstacle. This will enable simultaneous changing transformation of the node and the obstacle. For example:如果障碍物与应绕过的动态变化节点连接,则应将此节点设置为障碍物的父节点。 这将实现节点和障碍物的同时变化变换。 例如:

源代码 (C#)
#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Vec4 = Unigine.dvec4;
using Mat4 = Unigine.dmat4;
#else
	using Vec3 = Unigine.vec3;
	using Vec4 = Unigine.vec4;
	using Mat4 = Unigine.mat4;
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class Route : Component
{
	// declare the required variables
	ObstacleBox box_obstacle;
	ObjectMeshStatic box;
	PathRoute route;

	// declare points between which a route should be calculated
	Vec3 p0 = new Vec3(-60.0f, -60.0f, 5.0f);
	Vec3 p1 = new Vec3(60.0f, 60.0f, 5.0f);

	private void Init()
	{
		// enable the engine visualizer
		Visualizer.Enabled = true;

		// create a navigation sector within which pathfinding will be performed
		NavigationSector navigation = new NavigationSector(new vec3(128.0f, 128.0f, 8.0f));
		navigation.WorldTransform = MathLib.Translate(new Vec3(1.0f, 1.0f, 5.0f));

		// create the ObjectMeshStatic that should be bypassed
		box = new ObjectMeshStatic("core/meshes/box.mesh");

		box.Position = new Vec3(2.0f, 2.2f, 1.5f);
		box.Scale = new vec3(2.0f, 2.0f, 2.0f);

		// create an obstacle
		box_obstacle = new ObstacleBox(new vec3(1.2f, 1.2f, 1.2f));

		box_obstacle.Position = new Vec3(0.0f, 0.0f, 0.0f);
		// add the obstacle as the child node to the mesh in order to change their transformation simultaneously
		box.AddChild(box_obstacle);

		// create a new route
		route = new PathRoute();
		// set a radius for the point which will move along the route
		route.Radius = 1.2f;
	}

	private void Update()
	{
		 // get the frame duration
		float ifps = Game.IFps;
		// and define the angle of the object's rotation
		float angle = ifps * 90.0f;

		// change transformation of the mesh
		box.Transform = box.Transform * new Mat4(MathLib.RotateZ(angle));
		// render the bounding box of the obstacle
		box_obstacle.RenderVisualizer();

		// recalculate the route in the current frame and render its visualizer
		route.Create2D(p0, p1);
		route.RenderVisualizer(new vec4(1.0f));
		
	}
}
注意
In the example above, the route is recalculated each frame. However, it is non-optimal for application performance. You can calculate the route, for example, once per 10 frames.在上面的示例中,每个帧都会重新计算路由。 但是,它对于应用程序性能来说不是最佳的。 例如,可以每10帧计算一次路由。

As a result, you will have a simple navigation sector, in which the dynamically changing obstacle box is placed.最终,您将有一个简单的导航扇区,其中放置了动态变化的障碍框。

Here the obstacle is highlighted with red在这儿,障碍用红色突出显示

本页面上的信息适用于 UNIGINE 2.19.1 SDK.

最新更新: 2024-12-13
Build: ()