Of course! I’m happy to help!
Success!
I just put out version 15, which includes the directional NavGo nodes with labels to identify their number.
Please note, this only works during runtime, outside of runtime, all nodes will just display their ID as #, changing any one label will change all of them. For example, changing one label to “#1” changes all of the labels that refer to that specific game object.
The way to prevent this change is to create your own game object and add all of the parts to it like this:
- Open up your collection and right click in the outline on the word “collection”
- Right click on the new game object you created and click on “add component file”, you will want to add in the directional NavGo script to the game object.
- Right click on the new game object and hover over “add component”, this will open up a small side window where you need to select a sprite and a label.
- Within the sprite component, set the image to the NavGo atlas (/navGo_pathfinding/navGOAtlas.atlas) and set the default animation to be the directional node.
- Within the label component, set the Id to be “IdNumber”. Change the color to black. Change the position to be 0,0,.1 (this will show the label above the sprite). Change the text to be whatever you want on the node. Change the size to be 64,64,0. Set the font to be this link: /navGo_pathfinding/NavGOAssets/24-point-font.font
- Now you can cut/copy and paste this node and treat it like any other type of directional node, except that it can now have a different label in the editor. You should be able to even copy this across different collections to save yourself from having to do this in every level.
This is the end result of the above steps:
Today I was working on adding different enemies and the program started acting weird. So I reloaded the program as made yesterday which worked. Today though the same program no longer works. I added a print scripts showing what the characterGO stated as start and end and they all seem fine. But none of the objects will move. No nodes have been altered, I did not mess with any labels etc.
INFO:DLIB: Log server started on port 56845
INFO:ENGINE: Target listening with name: DESKTOP-T9J0991 - fe80::6864:d0a8:85fb:42cf - Windows
INFO:ENGINE: Engine service started on port 56846
INFO:ENGINE: Defold Engine 1.2.178 (af6a29c)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: Listening for debugger on 0.0.0.0
DEBUG:SCRIPT: Debugger connected from 127.0.0.1
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
INFO:DLIB: SSDP: Started on address 192.168.0.2
INFO:DLIB: SSDP: Started on address 192.168.56.1
DEBUG:SCRIPT: WARNING: NODE url: [main:/NavGO_NodeGO#NavGO_NodeScript] does not have any connections within range.
DEBUG:SCRIPT: -- NavGo is ready to be used
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
Main Script:
function init(self)
local message = {}
message.collisions = { hash("wall") }
message.debug = false
message.deleteNodeAfterGotten = true
message.nodeNeighborRange = 500
message.nodeNeighborRange = 500
msg.post("/NavGO_HandlerGO#NavGO_HandlerScript", hash("init"), message)
timer.delay(1, true, function()
local url = "#factory"
local position = vmath.vector3(200, 200, 0) -- position where character spawns
local rotation = vmath.quat_rotation_z(0) --quat angle the character spawns at
local properties = { Start_path_ID = 1, End_path_ID = 100, speed = 400 } -- table of values to send to object
local scale = vmath.vector3(0.5, 0.5, 0.51) -- scale to spawn at
factory.create(url, position, rotation, properties, scale)
end
)
end
function on_message(self, message_id, message, sender)
if message_id == hash("NavGO_Ready") then
print("-- NavGo is ready to be used")
-- Add game start code
end
end
character script
require("navGo_pathfinding.NavGO_Global")
go.property("Start_path_ID", -1)
go.property("End_path_ID", -1)
go.property("speed", 400)
local function distance(vec1, vec2)
return math.ceil( math.sqrt( math.pow(vec1.x - vec2.x, 2) + math.pow(vec1.y - vec2.y, 2) ) )
end
local function moveCharacter(self)
local path, found = NAVGO.GET_PATH_FROM_DIRECTIONAL_ID(self.Start_path_ID, self.End_path_ID)
if not found then
print("Directional - NO PATH FOUND")
else
print("Directional - PATH FOUND")
local delay = 0
local lastPos = go.get_position(go.get_id())
for i=1, #path do
local newPosition = vmath.vector3(path[i].x, path[i].y, 1)
local time = distance(newPosition, lastPos) / self.speed -- move at a consistend speed
go.animate(go.get_id(), "position", go.PLAYBACK_ONCE_FORWARD, newPosition, go.EASING_LINEAR, time, delay)
lastPos = newPosition
delay = delay + time
end
--timer.delay(delay, false, moveCharacter)
end
end
------------------
--Core functions--
------------------
function init(self)
timer.delay(1, false, moveCharacter)
print("start")
print(self.Start_path_ID)
print("end")
print(self.End_path_ID)
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.group == hash("wall") then
local newpos = go.get_position() + message.normal * message.distance
go.set_position(newpos)
end
end
end
That is super strange, I don’t see anything wrong with the code your provided. Based on the fact you reverted to an older version that used to work, that suggests a problem with the NavGo itself. Curiously enough, your prints do say that a path has been found from “Directional - PATH FOUND” message. If I had to make an educated guess, there is some sort of bug in my NavGo that I will look into.
Here are some possible fixes:
- Try to change the master dependency to a versioned release, I suggest Alpha.13 : https://github.com/DrCampbell2017/NavGO/archive/Alpha.13.zip . This version doesn’t have the labels added in, but you should be able to check if it works or not. If it does, that means there is a problem with the NavGo I need to look into. Keep progressing forward with the versioned released until you hit one which doesn’t work.
- In the character.script, add a print statement before the for loop like this:
print(“Number of nodes in path” … tostring(#path))
That should show you how long the path is, if it prints 0 or nil, some sort of error has occurred I’ll need to patch.
As a side node, you can removed this chunk of code from the character.script. This code does not effect the NavGo but could cause something to get stuck if you have a collision group called “wall”.
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.group == hash("wall") then
local newpos = go.get_position() + message.normal * message.distance
go.set_position(newpos)
end
end
end
Any more information you could provide me would be helpful. Please let me know what you figure out!
I went back ver 11 and its working.
I was going to work forward there and see what happens.
print(“Number of nodes in path” … tostring(#path))
this doesnt work: /main/directional_character/directionalCharacterSingleton.script
Line 20: Compilation failed: unexpected symbol near ‘…’
My bad, that’s a typo should be:
print(“Number of nodes in path” .. tostring(#path)) --2 dots now instead of 3
The last change I made to the NavGo handler was version 12, after that, everything I changed was node-side such as adding in labels. I’m running tests now to see what could have changed elsewhere.
ver 13: obj shows up but doesnt move
DEBUG:SCRIPT: Number of nodes in path10
DEBUG:SCRIPT: is calling go.animate
DEBUG:SCRIPT: start
DEBUG:SCRIPT: 1
DEBUG:SCRIPT: end
DEBUG:SCRIPT: 100
DEBUG:SCRIPT: Directional - PATH FOUND
DEBUG:SCRIPT: Number of nodes in path10
DEBUG:SCRIPT: is calling go.animate
INFO:DLIB: SSDP: Done on address 192.168.0.2
INFO:DLIB: SSDP: Done on address 192.168.56.1
It’s super strange to me that version 12 runs but 13 doesn’t. Everything is still working fine within the sample project on my end. If you download the master branch from github and run the sample project, does it still work on your end?
Maybe this will help you see if its my code or yours.
Yes I can run the sample codes and edit them.
The reason why Im fixated on this one is to see why it happened- if I accidently overwrote something or id it is a bug. So I can avoid in future.
BTW what time is it where you are? 2am here.
It’s 3am here, I may call it a night soon.
Some thing I noticed, the enemy node you have is still moving, if I add in an update function like this:
function update(self, dt)
print("My position is: " .. tostring( go.get_position() ))
end
You can see the position changing as it moves across the screen. Stranger still, is that when you change the timer in the main script from repeat = true to repeat = false. The character just seems to vanish.
I figured it out, kinda. When I change this line from within the character script from
local newPosition = vmath.vector3(path[i].x, path[i].y, 1)
to:
local newPosition = vmath.vector3(path[i].x, path[i].y, 0)
The node is visible and will travel around the screen properly. It existed the entire time but was somehow being rendered out, with the new node spawning every second, and the old node waiting a full second to move, it gave the appearance of it not moving while it was moving just above or bellow the render area. I am fully lost on why this happens between version 12 and 13, but it is still working, which I think is a good thing.
Thank ye kind sir Im ready for bed to. Had my chemo pump removed today and Im worn down. Ill check into this morrow.
This is a good learning experience for me. Education comes with pain.
Edit: Yep that worked!
Good night!
Congrats on getting the chemo pump removed!
To explain what happened and why the balloon was rendered out. Without using some form of camera plug-in or changing the render property, Defold will only render in objects between the z-axis of -1 and 1. The objects not rendered still exist and can move about, but will not be displayed to the player during runtime. With your project, the character was being moved to the z-axis of 1 by my NavGO, then having the sprite be at 1 also put it above the upper limit and caused it not to be displayed. If you wanted to leave the z-axis stuff alone, you can fix it by using something like this in the main.script:
msg.post("@render:", "use_stretch_projection", { near = -2, far = 2 })
I also recommend changing the background sprite you are using to a z-axis of -1 so that balloons don’t actually spawn under it.
Here’s a reference to the rendering: https://defold.com/manuals/render/
Here’s a reference to the camera component: https://defold.com/manuals/camera/
I recommend not touching either the rendering stuff or trying to program your own camera, it takes a lot of time and unless you have a highly specialized reason to do so, it is not the best use of time. I personally think it is better to use one of the camera plug-ins. I personally recommend this one by britzl : https://github.com/britzl/defold-orthographic
Thank you for answering my question before I asked it!
Updated proof it works
Thank you Dr Campbell for all your hard work on this project.
That looks great!
Thank you for using it! I’m glad it works well for your project, don’t be afraid to let me know if you need any bug fixes or features added to the library!