BGE Navigation Mesh

edit I posted this here, not sure if it belonged here or in BGE. I just assumed that, this being a Physics setting, it belonged here. I request it be moved by a moderator to BGE if it belongs there. edit

I’ve edited mesh data before using BPY, but what if we want to edit a mesh in the BGE?

What I’m trying to accomplish is updating the navigation mesh to account or impediments that no longer exist. A maze whose walls are added and removed (not moved, but literally added and removed) as time passes. I wanted to mess with the new(?) navigation mesh option, so I figured I’d try recreating Dungeon Keeper. In the game your Imps mine out blocks (similar to how blocks are mined in Minecraft) to create new passages and rooms. This is what I’m trying to achieve.

To be more clear…

Currently I have two methods of accounting for an obstacle. I can use the obstacle settings, to make the Agent avoid, say, a tree. This does not affect the Navigation Mesh. However, anything more complex than a small, fairly simple obstacle will turn your Agent into a pacing idiot, so I’ve found that to effectively account for more complex obstacles you just include it in the objects to generate your Navigation Mesh from.

This is what you would have to do for the walls in a maze, for instance. Mesh faces where a wall exists will be placed on top of that wall (literally above), not connected to any of the mesh faces on the floor. This effectively removes wall space from the main path. But what if that wall is removed? How can I include that space back into the main path?

Any ideas? Am I just missing something? Or is that all there is to it?

*edit - was getting further from where I wanted to be.

Currently I’m working with this information

KX_NavMeshObject - subclass of KX_GameObject
http://www.blender.org/documentation/blender_python_api_2_68_release/bge.types.KX_NavMeshObject.html

KX_SteeringActuator
http://www.blender.org/documentation/blender_python_api_2_68_release/bge.types.KX_SteeringActuator.html

If I could pass KX_SteeringActuator two meshes through navmesh(), or if I could “add” the mesh data of two meshes together in Python and pass that to KX_NavMeshObject, then I see how I could solve this problem.

So… right now, I’m attempting to write the logic in Python. The Desired Script returns an error (TypeError: KX_NAVMESHOBJECT is expected) in the terminal. So I simplified it, and just tried to set the Target and NavMesh using existing objects, and that also does not work. For the simple example, I JOINED both the nmField and the nmMaze. The simple example is first.


Simple Script (does not work)


import bge


owner = bge.logic.getCurrentController().owner
sensors = bge.logic.getCurrentController().sensors
actuators = bge.logic.getCurrentController().actuators
scene = bge.logic.getCurrentScene()


target = scene.objects['Goal Cheese']
navMesh = scene.objects['nmField']


actuators['Steering'].target = target
actuators['Steering'].navmesh = navMesh

Desired Script (does not work)


import bge


print ('Hello')


owner = bge.logic.getCurrentController().owner
sensors = bge.logic.getCurrentController().sensors
actuators = bge.logic.getCurrentController().actuators
scene = bge.logic.getCurrentScene()


steer = 1
flee = 2
pathfind = 3
target = scene.objects['Goal Cheese']


navMeshParts = []
navMeshParts.append(scene.objects['nmField'].meshes[0])
navMeshParts.append(scene.objects['nmMaze'].meshes[0])
baseObject = 'nmBase'
level = scene.objects['Ground']
pX = level.localPosition.x + .2
pY = level.localPosition.y + .2
pZ = level.localPosition.z + .2


navMeshWhole = scene.addObject(baseObject, level)
navMeshWhole.meshes.append(navMeshParts)
navMeshWhole.localPosition = [pX, pY, pZ]


behavior = pathfind
target = target
navMesh = navMeshWhole
aquireDistance = 30.0
relaxDistance = 2.0
velocity = 4.0
acceleration = 1000.0
turning = 720.0


actuators['Steering'].behavior = behavior
actuators['Steering'].velocity = velocity
actuators['Steering'].acceleration = acceleration
actuators['Steering'].turnspeed = turning
actuators['Steering'].distance = relaxDistance
actuators['Steering'].target = target
actuators['Steering'].navmesh = navMesh

Attachments