Example #1
0
        void SetPathPoint()
        {
            var input = GetSubsystem <Input>();

            Vector3        hitPos;
            Drawable       hitDrawable;
            NavigationMesh navMesh = scene.GetComponent <NavigationMesh>();

            if (Raycast(250.0f, out hitPos, out hitDrawable))
            {
                Vector3 pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f));

                if (input.GetQualifierDown(Constants.QUAL_SHIFT))
                {
                    // Teleport
                    currentPath.Clear();
                    jackNode.LookAt(new Vector3(pathPos.X, jackNode.Position.Y, pathPos.Z), Vector3.UnitY, TransformSpace.TS_WORLD);
                    jackNode.Position = (pathPos);
                }
                else
                {
                    // Calculate path from Jack's current position to the end point
                    endPos = pathPos;
                    var result = navMesh.FindPath(currentPath, jackNode.Position, endPos);
                }
            }
        }
Example #2
0
        void AddOrRemoveObject()
        {
            // Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
            Vector3  hitPos;
            Drawable hitDrawable;

            if (Raycast(250.0f, out hitPos, out hitDrawable))
            {
                // The part of the navigation mesh we must update, which is the world bounding box of the associated
                // drawable component
                BoundingBox updateBox;

                Node hitNode = hitDrawable.Node;
                if (hitNode.Name == "Mushroom")
                {
                    updateBox = hitDrawable.WorldBoundingBox;
                    hitNode.Remove();
                }
                else
                {
                    Node newNode = CreateMushroom(hitPos);
                    updateBox = newNode.GetComponent <StaticModel>().WorldBoundingBox;
                }

                // Rebuild part of the navigation mesh, then recalculate path if applicable
                NavigationMesh navMesh = scene.GetComponent <NavigationMesh>();
                navMesh.Build(updateBox);
                if (currentPath.Count > 0)
                {
                    navMesh.FindPath(currentPath, jackNode.Position, endPos);
                }
            }
        }
Example #3
0
        void SetPathPoint()
        {
            Vector3        hitPos;
            Drawable       hitDrawable;
            NavigationMesh navMesh = scene.GetComponent <NavigationMesh>();

            if (Raycast(250.0f, out hitPos, out hitDrawable))
            {
                Vector3 pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f));

                const int qualShift = 1;
                if (Input.GetQualifierDown(qualShift))
                {
                    // Teleport
                    currentPath.Clear();
                    jackNode.LookAt(new Vector3(pathPos.X, jackNode.Position.Y, pathPos.Z), Vector3.UnitY, TransformSpace.World);
                    jackNode.Position = (pathPos);
                }
                else
                {
                    // Calculate path from Jack's current position to the end point
                    endPos = pathPos;
                    var result = navMesh.FindPath(jackNode.Position, endPos);
                    currentPath = new List <Vector3>(result);
                }
            }
        }