I apologize for spamming two forums with this, now. I wasn’t sure where to post this, so initially I posted it in Support>Physics, as this is a physics-related question, sort of. I decided to start one here, as I’m not entirely sure the other one even belonged there, let alone was receiving views from people who knew any answers.
http://www.blenderartists.org/forum/showthread.php?301903-BGE-Navigation-Mesh
The objective is to “uncover” additional NavMesh… ‘space’, I suppose. If any of you can remember back to Dungeon Keeper your imps would mine out walls and create additional paths. I’m attempting to achieve a similar mechanic. However, to keep Navigation updated for the imps, I would need to add the space that is now uncovered (wall removed) to the current Navigation Mesh.
Currently, with the basic method I use of using all scene objects to create the NavMesh from the Scene Panel, the Agent moves from his starting point in the “Field”, through the maze, and to his finishing point at the “Goal Cheese”.
The problem is that I can’t seem to be able to edit the NavMesh in real-time, this due to the BGE’s inability to interact with Blender, though I did find something about RAS_MeshObject somewhere - something that I can’t seem to find any documentation on…
The following is the current version of my script. It does not work, though it returns no errors in the Terminal. I have two scripts, now. One to generate the NavMesh, the second to commit it to the Steering Actuator on the agent.
NavMesh Generation
import bge
print ('ASSEMBLING NAVMESH')
print ('Getting scene data')
owner = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()
print ('Configuring navMesh parts')
navMeshParts = []
#NavMesh from the field
navMeshParts.append(scene.objects['nmField'].meshes[0])
#NavMesh from the maze
navMeshParts.append(scene.objects['nmMaze'].meshes[0])
baseObject = 'nmBase'
meshLoc = scene.objects['Ground']
pX = meshLoc.localPosition.x + .2
pY = meshLoc.localPosition.y + .2
pZ = meshLoc.localPosition.z + .2
print ('Assembling the NavMesh')
navMeshWhole = scene.addObject(baseObject, meshLoc)
navMeshWhole.meshes.append(navMeshParts)
navMeshWhole.localPosition = [pX, pY, pZ]
print ('Committing NavMesh to KX_NavMeshObject')
navMesh = bge.types.KX_NavMeshObject(navMeshWhole)
print ('Assign NavMesh to Agent')
owner['navMesh'] = navMesh.name
Steering Configuration
import bge
keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
if keyboard.events[bge.events.SPACEKEY] == JUST_ACTIVATED:
print ('STEERING')
print ('Getting scene data')
owner = bge.logic.getCurrentController().owner
sensors = bge.logic.getCurrentController().sensors
actuators = bge.logic.getCurrentController().actuators
scene = bge.logic.getCurrentScene()
print ('Getting Target and NavMesh')
target = scene.objects['Goal Cheese']
navMesh = scene.objects[owner['navMesh']]
print ('Assigning data to Actuator')
actuators['Steering'].target = target
actuators['Steering'].navmesh = navMesh
path = navMesh.findPath(owner.localPosition, target.localPosition)
Neither script returns errors in the console. However, attempting to print out ‘path’ returns an empty array. If I replace
navMesh = scene.objects[owner['navMesh']]
with
navMesh = scene.objects['nmField']
I DO get a returned array of points along the path (for the field, but not the maze). This tells me I can’t pass two meshes in one object to KX_NavMeshObject. Either that, or I’m not passing something to NavMeshObject that I should be.
Help!!!