age-of-asparagus/godot3-3dgame

e2.6 Map Navigation

Closed this issue · 2 comments

Full SCreen
Big Txt

Compare level.tsn to the LevelGenerator

  • Base node is Navigation/NavigationMeshInstance
var level: Navigation
var navmesh_instance: NavigationMeshInstance
func add_level():
	level = Navigation.new()
	level.name = "Navigation"
	add_child(level)
	level.owner = self
	
	# Add navmesh
	navmesh_instance = NavigationMeshInstance.new()
	level.add_child(navmesh_instance)
	navmesh_instance.owner = self
	
	# navmesh resource
	var navmesh := NavigationMesh.new()
	navmesh_instance.navmesh = navmesh

func add_ground():
	var ground: CSGBox = GroundScene.instance()
	ground.width = map_width * 2
	ground.depth = map_depth * 2 
	navmesh_instance.add_child(ground)   #####################################
	ground.owner = self

        ########### SAME WITH ADD OBSTACLES

func create_obstacle_at(x, z):
	var obstacle_position = Vector3(x * 2, 0, z * 2)
       # ...
	
	new_obstacle.transform.origin = obstacle_position + Vector3(0, new_obstacle.height/2, 0)
	navmesh_instance.add_child(new_obstacle) ###########################################
	new_obstacle.owner = self

Need to make Nav owner of navmesh_instance for saving

func set_save_level(new_val):
	var packed_scene = PackedScene.new()
#############
	navmesh_instance.owner = level
	for child in navmesh_instance.get_children():
		child.owner = level
##############
	packed_scene.pack(level)
	var scene_resource_path = "res://Level/LevelGenerator/GeneratedLevels/%s.tscn" % level_name
	ResourceSaver.save(scene_resource_path, packed_scene)

COmment on

  • Low obstacle heights
    --Save as "Level1"