godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.65k stars 1.58k forks source link

'Navigation Polygon 2D' ported to Godot 4.1.1 #955

Closed Alex2782 closed 10 months ago

Alex2782 commented 11 months ago

I have combined the script from the documentation with the old solution (click event with red dot) https://docs.godotengine.org/en/latest/tutorials/navigation/navigation_introduction_2d.html#setup-for-2d-scene

https://github.com/godotengine/godot-demo-projects/assets/41921395/a21e9ab1-43e1-4c0b-820a-563a8ee23264

'NavigationPolygon' drawn again, it looked buggy. image

Alex2782 commented 11 months ago

how to fix these errors?

image

Calinou commented 11 months ago

You have trailing whitespace (tabs) in your code. I recommend enabling the Trim Trailing Whitespace on Save editor setting to get rid of them automatically :slightly_smiling_face:

smix8 commented 11 months ago

If we rework and update the demo maybe we should save the NavigationPolygon resource to an external file as a binary .res file?

Right now it is stored embedded as plain text inside the navigation.tscn file, something that we should not teach to new users as it will bloat their scene files and make them super slow to load/save/update on large and complex navigation meshes.

Alex2782 commented 11 months ago

@smix8 it's now an external file, but i forgot to configure properly to res, it's now tres (text), should we leave it like that? maybe better for github and debbugging? I don't know yet how to convert tres to res afterwards, does Godot already have a function for that?

Save as, or convert to function would perhaps be quite good in the context menu. image

smix8 commented 11 months ago

don't know yet how to convert tres to res afterwards

Click the "Make Unique" again and "Save As" then you can save it as a new .res binary file.

Alex2782 commented 11 months ago

@smix8 The function set_movement_target was already in the character-GDscript, but unused (copied from the doc) I moved the character to its own scene and deleted navigation.gd.

now only one script character.gd

navigation_agent.debug_enabled = true 👍

https://github.com/godotengine/godot-demo-projects/assets/41921395/37e8388b-d4f5-4f6a-91c1-dbdd5b06d3fb