Exemple #1
0
 public void Deserialize(DeserializeEvent e)
 {
     EntityID         = e.Reader.ReadUInt32();
     Path             = e.Reader.ReadSerializable <SmoothPath>();
     Speed            = e.Reader.ReadSingle();
     StoppingDistance = e.Reader.ReadSingle();
 }
Exemple #2
0
 public TestSceneSliderPath()
 {
     Child = drawablePath = new SmoothPath
     {
         Anchor = Anchor.Centre,
         Origin = Anchor.Centre
     };
 }
 private void Start()
 {
     if (lineRenderer != null)
     {
         lineRenderer = GetComponent <LineRenderer>();
     }
     path = waypointMovement.Path;
 }
Exemple #4
0
 public void TestSmoothPath()
 {
     AddStep("create path", () =>
     {
         Child = new SmoothPath
         {
             Anchor     = Anchor.Centre,
             Origin     = Anchor.Centre,
             PathRadius = 10,
             Vertices   = new List <Vector2>
             {
                 Vector2.Zero,
                 new Vector2(200)
             },
         };
     });
 }
            public ControlPointVisualiser()
            {
                RelativeSizeAxes = Axes.Both;

                InternalChildren = new Drawable[]
                {
                    path = new SmoothPath
                    {
                        PathRadius = 1,
                        Colour     = Color4.Yellow.Opacity(0.5f)
                    },
                    new PointHandle
                    {
                        PointPosition = { BindTarget = PointPosition }
                    }
                };
            }
Exemple #6
0
	// Use this for initialization
	void Start () 
	{
		path = new SmoothPath(14);
		path.SetPoint(0, new Vector2(40.0f, 12.51211f));
		path.SetPoint(1, new Vector2(27.31694f, 15.50579f));
		path.SetPoint(2, new Vector2(0.0f, 13.1085f));
		path.SetPoint(3, new Vector2(31.02438f, 8.70939f));
		path.SetPoint(4, new Vector2(29.4586f, 4.315308f));
		path.SetPoint(5, new Vector2(24.59858f, 4.947972f));
		path.SetPoint(6, new Vector2(19.33292f, 4.624193f));
		path.SetPoint(7, new Vector2(15.29456f, 4.902945f));
		path.SetPoint(8, new Vector2(13.39676f, 6.435778f));
		path.SetPoint(9, new Vector2(12.84386f, 8.886725f));
		path.SetPoint(10, new Vector2(9.424064f, 8.247343f));
		path.SetPoint(11, new Vector2(9.531949f, 4.741022f));
		path.SetPoint(12, new Vector2(11.28376f, 1.784844f));
		path.SetPoint(13, new Vector2(19.87172f, 1.2862f));

		path.SetCurveRadius(0, 5.0f);
		path.SetCurveRadius(1, 1.35f);
		path.SetCurveRadius(2, 2.0f);
		path.SetCurveRadius(3, 2.0f);
		path.SetCurveRadius(4, 5.0f);
		path.SetCurveRadius(5, 5.0f);
		path.SetCurveRadius(6, 3.0f);
		path.SetCurveRadius(7, 2.0f);
		path.SetCurveRadius(8, 1.0f);
		path.SetCurveRadius(9, 2.0f);
		path.SetCurveRadius(10, 5.0f);
		path.SetCurveRadius(11, 2.0f);

		path.Init();

		monsters = new List<Monster>();

		GameObject go = Instantiate(goblin) as GameObject;
		Monster monster = go.GetComponent<Monster>();
		monster.path = path;
		monster.terrainData = terrainCollider.terrainData;

		monsters.Add(monster);
	}
Exemple #7
0
    public static SmoothPath ComputeSmoothPath(Detour.dtNavMeshQuery navQuery, float[] startWorldPos, float[] endWorldPos, float distance = 10)
    {
        SmoothPath smoothPath = new SmoothPath();

        if (navQuery == null)
        {
            return(smoothPath);
        }

        float[] extents = new float[3];
        for (int i = 0; i < 3; ++i)
        {
            extents[i] = distance;
        }

        dtPolyRef startRef = 0;
        dtPolyRef endRef   = 0;

        float[] startPt = new float[3];
        float[] endPt   = new float[3];

        Detour.dtQueryFilter filter = new Detour.dtQueryFilter();

        navQuery.findNearestPoly(startWorldPos, extents, filter, ref startRef, ref startPt);
        navQuery.findNearestPoly(endWorldPos, extents, filter, ref endRef, ref endPt);

        const int maxPath = SmoothPath.MAX_POLYS;

        dtPolyRef[] path = new dtPolyRef[maxPath];

        int pathCount = -1;

        navQuery.findPath(startRef, endRef, startPt, endPt, filter, path, ref pathCount, maxPath);

        smoothPath.m_nsmoothPath = 0;

        if (pathCount > 0)
        {
            // Iterate over the path to find smooth path on the detail mesh surface.
            dtPolyRef[] polys = new dtPolyRef[SmoothPath.MAX_POLYS];
            for (int i = 0; i < pathCount; ++i)
            {
                polys[i] = path[i];
            }
            int npolys = pathCount;

            float[] iterPos           = new float[3];
            float[] targetPos         = new float[3];
            bool    posOverPoly_dummy = false;
            navQuery.closestPointOnPoly(startRef, startPt, iterPos, ref posOverPoly_dummy);
            navQuery.closestPointOnPoly(polys[npolys - 1], endPt, targetPos, ref posOverPoly_dummy);

            const float STEP_SIZE = 0.5f;
            const float SLOP      = 0.01f;

            smoothPath.m_nsmoothPath = 0;

            Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, iterPos, 0);
            smoothPath.m_nsmoothPath++;

            // Move towards target a small advancement at a time until target reached or
            // when ran out of memory to store the path.
            while (npolys != 0 && smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
            {
                // Find location to steer towards.
                float[]   steerPos     = new float[3];
                byte      steerPosFlag = 0;
                dtPolyRef steerPosRef  = 0;

                if (!getSteerTarget(navQuery, iterPos, targetPos, SLOP,
                                    polys, npolys, steerPos, ref steerPosFlag, ref steerPosRef))
                {
                    break;
                }

                bool endOfPath         = (steerPosFlag & (byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_END) != 0 ? true : false;
                bool offMeshConnection = (steerPosFlag & (byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 ? true : false;

                // Find movement delta.
                float[] delta = new float[3];                //, len;
                float   len   = .0f;
                Detour.dtVsub(delta, steerPos, iterPos);
                len = (float)Mathf.Sqrt(Detour.dtVdot(delta, delta));
                // If the steer target is end of path or off-mesh link, do not move past the location.
                if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
                {
                    len = 1;
                }
                else
                {
                    len = STEP_SIZE / len;
                }
                float[] moveTgt = new float[3];
                Detour.dtVmad(moveTgt, iterPos, delta, len);

                // Move
                float[]     result   = new float[3];
                dtPolyRef[] visited  = new dtPolyRef[16];
                int         nvisited = 0;
                navQuery.moveAlongSurface(polys[0], iterPos, moveTgt, filter,
                                          result, visited, ref nvisited, 16);

                npolys = fixupCorridor(polys, npolys, SmoothPath.MAX_POLYS, visited, nvisited);
                npolys = fixupShortcuts(polys, npolys, navQuery);

                float    h = 0;
                dtStatus getHeightStatus = navQuery.getPolyHeight(polys[0], result, ref h);
                result[1] = h;

                if ((getHeightStatus & Detour.DT_FAILURE) != 0)
                {
                    Debug.LogError("Failed to getPolyHeight " + polys[0] + " pos " + result[0] + " " + result[1] + " " + result[2] + " h " + h);
                }

                Detour.dtVcopy(iterPos, result);

                // Handle end of path and off-mesh links when close enough.
                if (endOfPath && inRange(iterPos, 0, steerPos, 0, SLOP, 1.0f))
                {
                    // Reached end of path.
                    Detour.dtVcopy(iterPos, targetPos);
                    if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                    {
                        Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, iterPos, 0);
                        smoothPath.m_nsmoothPath++;
                    }
                    break;
                }
                else if (offMeshConnection && inRange(iterPos, 0, steerPos, 0, SLOP, 1.0f))
                {
                    // Reached off-mesh connection.
                    float[] startPos = new float[3];                    //, endPos[3];
                    float[] endPos   = new float[3];

                    // Advance the path up to and over the off-mesh connection.
                    dtPolyRef prevRef = 0, polyRef = polys[0];
                    int       npos = 0;
                    while (npos < npolys && polyRef != steerPosRef)
                    {
                        prevRef = polyRef;
                        polyRef = polys[npos];
                        npos++;
                    }
                    for (int i = npos; i < npolys; ++i)
                    {
                        polys[i - npos] = polys[i];
                    }

                    npolys -= npos;

                    // Handle the connection.

                    dtStatus status = navQuery.getAttachedNavMesh().getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos);
                    if (Detour.dtStatusSucceed(status))
                    {
                        if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                        {
                            Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, startPos, 0);
                            smoothPath.m_nsmoothPath++;
                            // Hack to make the dotted path not visible during off-mesh connection.
                            if ((smoothPath.m_nsmoothPath & 1) != 0)
                            {
                                Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, startPos, 0);
                                smoothPath.m_nsmoothPath++;
                            }
                        }
                        // Move position at the other side of the off-mesh link.
                        Detour.dtVcopy(iterPos, endPos);
                        float eh = 0.0f;
                        navQuery.getPolyHeight(polys[0], iterPos, ref eh);
                        iterPos[1] = eh;
                    }
                }

                // Store results.
                if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                {
                    Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, iterPos, 0);
                    smoothPath.m_nsmoothPath++;
                }
            }
        }
        return(smoothPath);
    }
Exemple #8
0
 private void Awake()
 {
     path = GetComponent <WaypointMovement>().Path;
 }
            public CurveVisualiser()
            {
                easingFunction = new CustomEasingFunction {
                    EasingVertices = { BindTarget = easingVertices }
                };

                Container gridContainer;

                InternalChildren = new Drawable[]
                {
                    new Container
                    {
                        RelativeSizeAxes = Axes.Both,
                        Masking          = true,
                        BorderColour     = Color4.White,
                        BorderThickness  = 2,
                        Child            = new Box
                        {
                            RelativeSizeAxes = Axes.Both,
                            Alpha            = 0,
                            AlwaysPresent    = true
                        }
                    },
                    gridContainer = new Container {
                        RelativeSizeAxes = Axes.Both
                    },
                    path = new SmoothPath
                    {
                        PathRadius = 1
                    },
                    controlPointContainer = new Container <ControlPointVisualiser> {
                        RelativeSizeAxes = Axes.Both
                    },
                    sideTracker = new SpriteIcon
                    {
                        Anchor = Anchor.TopRight,
                        Origin = Anchor.BottomCentre,
                        RelativePositionAxes = Axes.Y,
                        Size     = new Vector2(10),
                        X        = 2,
                        Colour   = Color4.SkyBlue,
                        Rotation = 90,
                        Icon     = FontAwesome.Solid.MapMarker,
                    },
                    verticalTracker = new Box
                    {
                        Origin               = Anchor.CentreLeft,
                        RelativeSizeAxes     = Axes.X,
                        RelativePositionAxes = Axes.Y,
                        Height               = 1,
                        Colour               = Color4.SkyBlue
                    },
                    horizontalTracker = new Box
                    {
                        Origin               = Anchor.TopCentre,
                        RelativeSizeAxes     = Axes.Y,
                        RelativePositionAxes = Axes.X,
                        Width  = 1,
                        Colour = Color4.SkyBlue
                    }
                };

                for (int i = 0; i <= 10; i++)
                {
                    gridContainer.Add(new Box
                    {
                        Origin               = Anchor.CentreLeft,
                        RelativeSizeAxes     = Axes.X,
                        RelativePositionAxes = Axes.Y,
                        Height               = 2,
                        Y      = 0.1f * i,
                        Colour = Color4.White.Opacity(0.1f)
                    });

                    gridContainer.Add(new Box
                    {
                        Origin               = Anchor.TopCentre,
                        RelativeSizeAxes     = Axes.Y,
                        RelativePositionAxes = Axes.X,
                        Width  = 2,
                        X      = 0.1f * i,
                        Colour = Color4.White.Opacity(0.1f)
                    });
                }

                controlPointContainer.Add(new ControlPointVisualiser
                {
                    PointPosition = { Value = new Vector2(100, 100) }
                });
            }
Exemple #10
0
    public static SmoothPath ComputeSmoothPath(Detour.dtNavMeshQuery navQuery, float[] startWorldPos, float[] endWorldPos)
    {
        SmoothPath smoothPath = new SmoothPath();

        if (navQuery == null){
            return smoothPath;
        }

        float[] extents = new float[3];
        for (int i=0;i<3;++i){
            extents[i] = 10.0f;
        }

        dtPolyRef startRef = 0;
        dtPolyRef endRef = 0;

        float[] startPt = new float[3];
        float[] endPt = new float[3];

        Detour.dtQueryFilter filter = new Detour.dtQueryFilter();

        navQuery.findNearestPoly(startWorldPos, extents, filter, ref startRef, ref startPt);
        navQuery.findNearestPoly(endWorldPos, extents, filter, ref endRef, ref endPt);

        const int maxPath = SmoothPath.MAX_POLYS;
        dtPolyRef[] path = new dtPolyRef[maxPath];

        int pathCount = -1;

        navQuery.findPath(startRef, endRef, startPt, endPt, filter, path, ref pathCount, maxPath );

        smoothPath.m_nsmoothPath = 0;

        if (pathCount > 0)
        {
            // Iterate over the path to find smooth path on the detail mesh surface.
            dtPolyRef[] polys = new dtPolyRef[SmoothPath.MAX_POLYS];
            for (int i=0;i<pathCount;++i){
                polys[i] = path[i];
            }
            int npolys = pathCount;

            float[] iterPos = new float[3];
            float[] targetPos = new float[3];
            bool posOverPoly_dummy = false;
            navQuery.closestPointOnPoly(startRef, startPt, iterPos, ref posOverPoly_dummy);
            navQuery.closestPointOnPoly(polys[npolys-1], endPt, targetPos, ref posOverPoly_dummy);

            const float STEP_SIZE = 0.5f;
            const float SLOP = 0.01f;

            smoothPath.m_nsmoothPath = 0;

            Detour.dtVcopy(smoothPath.m_smoothPath,smoothPath.m_nsmoothPath*3, iterPos, 0);
            smoothPath.m_nsmoothPath++;

            // Move towards target a small advancement at a time until target reached or
            // when ran out of memory to store the path.
            while (npolys != 0 && smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
            {
                // Find location to steer towards.
                float[] steerPos = new float[3];
                byte steerPosFlag = 0;
                dtPolyRef steerPosRef = 0;

                if (!getSteerTarget(navQuery, iterPos, targetPos, SLOP,
                                    polys, npolys, steerPos, ref steerPosFlag, ref steerPosRef))
                    break;

                bool endOfPath = (steerPosFlag & (byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_END) != 0 ? true : false;
                bool offMeshConnection = (steerPosFlag & (byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 ? true : false;

                // Find movement delta.
                float[] delta = new float[3];//, len;
                float len = .0f;
                Detour.dtVsub(delta, steerPos, iterPos);
                len = (float)Mathf.Sqrt(Detour.dtVdot(delta,delta));
                // If the steer target is end of path or off-mesh link, do not move past the location.
                if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
                    len = 1;
                else
                    len = STEP_SIZE / len;
                float[] moveTgt = new float[3];
                Detour.dtVmad(moveTgt, iterPos, delta, len);

                // Move
                float[] result = new float[3];
                dtPolyRef[] visited = new dtPolyRef[16];
                int nvisited = 0;
                navQuery.moveAlongSurface(polys[0], iterPos, moveTgt, filter,
                                          result, visited, ref nvisited, 16);

                npolys = fixupCorridor(polys, npolys, SmoothPath.MAX_POLYS, visited, nvisited);
                npolys = fixupShortcuts(polys, npolys, navQuery);

                float h = 0;
                dtStatus getHeightStatus = navQuery.getPolyHeight(polys[0], result, ref h);
                result[1] = h;

                if ((getHeightStatus & Detour.DT_FAILURE) != 0) {
                    Debug.LogError("Failed to getPolyHeight " + polys[0] + " pos " + result[0] + " " + result[1] + " " + result[2] + " h " + h);
                }

                Detour.dtVcopy(iterPos, result);

                // Handle end of path and off-mesh links when close enough.
                if (endOfPath && inRange(iterPos, 0, steerPos, 0, SLOP, 1.0f))
                {
                    // Reached end of path.
                    Detour.dtVcopy(iterPos, targetPos);
                    if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                    {
                        Detour.dtVcopy(smoothPath.m_smoothPath,smoothPath.m_nsmoothPath*3, iterPos, 0);
                        smoothPath.m_nsmoothPath++;
                    }
                    break;
                }
                else if (offMeshConnection && inRange(iterPos, 0, steerPos, 0, SLOP, 1.0f))
                {
                    // Reached off-mesh connection.
                    float[] startPos = new float[3];//, endPos[3];
                    float[] endPos = new float[3];

                    // Advance the path up to and over the off-mesh connection.
                    dtPolyRef prevRef = 0, polyRef = polys[0];
                    int npos = 0;
                    while (npos < npolys && polyRef != steerPosRef)
                    {
                        prevRef = polyRef;
                        polyRef = polys[npos];
                        npos++;
                    }
                    for (int i = npos; i < npolys; ++i)
                        polys[i-npos] = polys[i];

                    npolys -= npos;

                    // Handle the connection.

                    dtStatus status = navQuery.getAttachedNavMesh().getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos);
                    if (Detour.dtStatusSucceed(status))
                    {
                        if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                        {
                            Detour.dtVcopy(smoothPath.m_smoothPath,smoothPath.m_nsmoothPath*3, startPos, 0);
                            smoothPath.m_nsmoothPath++;
                            // Hack to make the dotted path not visible during off-mesh connection.
                            if ((smoothPath.m_nsmoothPath & 1) != 0)
                            {
                                Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, startPos, 0);
                                smoothPath.m_nsmoothPath++;
                            }
                        }
                        // Move position at the other side of the off-mesh link.
                        Detour.dtVcopy(iterPos, endPos);
                        float eh = 0.0f;
                        navQuery.getPolyHeight(polys[0], iterPos, ref eh);
                        iterPos[1] = eh;
                    }
                }

                // Store results.
                if (smoothPath.m_nsmoothPath < SmoothPath.MAX_SMOOTH)
                {
                    Detour.dtVcopy(smoothPath.m_smoothPath, smoothPath.m_nsmoothPath * 3, iterPos, 0);
                    smoothPath.m_nsmoothPath++;
                }
            }
        }
        return smoothPath;
    }
 public UpdateFollowPathWithAstar(FollowPathOfPoints Follow, PathFindAStar AStar, obstacle_data[] obstacles)
 {
     follow     = Follow;
     aStar      = AStar;
     smoothPath = new SmoothPath(obstacles);
 }