Skip to content

Commit

Permalink
Navigation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karel Hovorka authored and hovi committed Dec 4, 2022
1 parent b6975b3 commit 9e44985
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,20 @@ class CharacterNavigation(
error("Graph is empty!")
}

val maxAllowedDistance = LARGE_BLOCK_CUBE_SIDE_SIZE * 1.15
val targetNode = graph.nodes
.minByOrNull { it.data.distanceTo(target.position) } ?: error("Target not found in the graph")
if (targetNode.data.distanceTo(target.position) > LARGE_BLOCK_CUBE_SIDE_SIZE) {
if (targetNode.data.distanceTo(target.position) > maxAllowedDistance) {
error(
"Target block $id is too far, distance to the closest navigable node: ${
targetNode.data.distanceTo(
target.position
)
}, (${targetNode.id})"
}, (${targetNode.id}). Allowed max distance is ${maxAllowedDistance}"
)
}

val startNode = allBlocks.minByOrNull { it.position.distanceTo(blockObservation.character.position) }
val graphNodes = graph.nodes.map { it.id }
val startNode = allBlocks.filter { it.id in graphNodes}.minByOrNull { it.position.distanceTo(blockObservation.character.position) }
?: error("No nodes found!")

val path = pathFinder.findPath(graph.toDirectedGraph(), targetNode.id, startNode.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LabRecruitsMapBuilder(
val gridId = mapPlacer.generate()
createGroups(gridId, map)
mapButtons(map)
sleep(50)
sleep(1500)
closeAllDoors(gridId, map)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package spaceEngineers.util.generator.map

import kotlinx.coroutines.runBlocking
import spaceEngineers.controller.SpaceEngineersJavaProxyBuilder
import spaceEngineers.controller.extend
import spaceEngineers.labrecruits.LabRecruitsController


fun main() = runBlocking {
val batch = SpaceEngineersJavaProxyBuilder().localhost()
val se = batch.extend()
val labRecruitsController = LabRecruitsController(se)
with(labRecruitsController) {
println("goto b0")
goToButton("b0")

println("press b0")
pressButton("b0")

println("goto door0")
goToDoor("door0")

println("goto door1")
goToDoor("door1")
}

}
9 changes: 4 additions & 5 deletions Source/Ivxr.SePlugin/Navigation/NavGraphEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public FatNavGraph GetGraph(string gridId)

// Get some look-ahead
var sphere = m_lowLevelObserver.GetBoundingSphere(null, m_lowLevelObserver.Radius * 3d);

// TODO: offset the start position to be below the character's feet
var orientationUp = GuessWhichSideIsUp(sourceGrid);
return CreateGraph(m_lowLevelObserver.ConvertToSeGrid(sourceGrid, sphere),
m_lowLevelObserver.CurrentPlayerPosition(),
GuessWhichSideIsUp(sourceGrid));
m_lowLevelObserver.CurrentPlayerPosition() - orientationUp * 2.5,
orientationUp);
}

internal FatNavGraph CreateGraph(CubeGrid grid, Vector3D start, Vector3I up)
Expand All @@ -75,7 +75,6 @@ internal FatNavGraph CreateGraph(CubeGrid grid, Vector3D start, Vector3I up)

map[currentPosition].Visited = true;

// check for obstacles (2 blocks above the site)
if (IsObstructed(currentPosition, map, up))
continue;

Expand Down

0 comments on commit 9e44985

Please sign in to comment.