Hi everyone,
Iam new here, so just a hi to all for starter:D
you probably noticed, english not my native, so sorry for wrong spelling and grammar.
anywho..
I try to get procedural navigation working. I found some information and videso but still am confused in many points.
one thing I still dont get is the order navmeshinstance<>navmesh
So far I got it like this
Navigation
|-NavigationMeshInstance
.....|-meshinstance
I set all settings in NavigationMeshInstance like agent radius and cell size to 0.1 so when I bake NavigationMesh it almost fills the whole plane.
it has a border of 0.2
as far as I understand it that way the are in the plane ist the navigateable are.
I saved it as scene and then I create a small are 5x5 and use startvec and endvec for test.
Somehow I got it working for the initial get_simple_path(startVec,endVec). It will produce a viable array and the navigation works.
Even on 20x20 field with some cut outs, it finds correct way. but a second call of get_simple_path(startVec,endVec) will produce empty array. So I am not sure if i have to reset the navigation node, or would have to recreate the navigation or i have a wrong order and the initial run just works by some strange chance or it is just some issue in godot 3.1.1(i use that version btw :D)
any hint would be apreciated. thank you
here the code for nav
extends Navigation
export (PackedScene) var baseNavMEsh
onready var startVec=Vector3(0,0,0.5)
onready var endVec=Vector3(3.2,0,0.8)
onready var pathToGo=[]
onready var pathToGoCounter=0
# Called when the node enters the scene tree for the first time.
func _ready():
#startVec=$player.global_transform.origin
for y in range(0,5):
for x in range(0,5):
var tmpPos=Vector2(x,y)
adjustNavMesh(tmpPos)
pathToGo=get_simple_path(startVec,endVec)
print(pathToGo)#initial call will create viable path
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#pass
func _physics_process(delta):
if(pathToGo.size()>pathToGoCounter):
var direction =(pathToGo[pathToGoCounter])-$player.global_transform.origin
if(direction.length()<0.2):
pathToGoCounter+=1
$player.move_and_slide(direction.normalized()*2,Vector3.UP)
print(get_simple_path(startVec,endVec))#just temporary to check what is created. always empty []
pass
func adjustNavMesh(whereTo):
var tmpNavMesh=baseNavMEsh.instance()
add_child(tmpNavMesh)
tmpNavMesh.translation.z+=whereTo.y*0.8
tmpNavMesh.translation.x+=whereTo.x*0.8
var tmpTransform=tmpNavMesh.transform
navmesh_add(tmpNavMesh.navmesh,tmpTransform)
pass
func recalcPath(whereToGo):
print(pathToGo)
endVec=whereToGo
startVec=$player.global_transform.origin
print(startVec," ",endVec)
pathToGo=get_simple_path(startVec,endVec)
pathToGoCounter=0
print(pathToGo.size())
pass