This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
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
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Creating Routes

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.

Warning
3D navigation feature is experimental and not recommended for production use.

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.

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.

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:

Source code (C#)
// AppWorldLogic.cs

using Unigine;

#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

namespace UnigineApp
{
    class AppWorldLogic : WorldLogic
    {

        // declare the required variables
        ObstacleBox box;
        ObjectMeshStatic mesh;
        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);

        public override bool 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 a mesh by adding a box surface to it
            Mesh mesh_0 = new Mesh();
            mesh_0.AddBoxSurface("box_surface", new vec3(1.0f));
            // create the ObjectMeshStatic that should be bypassed
            mesh = new ObjectMeshStatic(mesh_0);

            mesh.SetMaterial("mesh_base", "*");
            mesh.Position = new Vec3(2.0f, 2.2f, 1.5f);
            mesh.Scale = new vec3(2.0f, 2.0f, 2.0f);

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

            box.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
            mesh.AddChild(box);

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

            return true;
        }

        public override bool Update()
        {
            // get the frame duration
            float ifps = Engine.ifps;
            // and define the angle of the object's rotation
            float angle = ifps * 90.0f;

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

            // recalculate the route in the current frame and render its visualizer
            route.Create2D(p0, p1);
            route.RenderVisualizer(new vec4(1.0f));

            return true;
        }
    }
}
Notice
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.

In the result, you will have a simple navigation sector, in which the dynamically changing obstacle box is placed.

Here the obstacle is highlighted with red
Last update: 2020-07-31
Build: ()