Thanks to the NavGo path finding asset and working with Dr. Campbell (And he was first class to work with), I now have a functional path system in Defold for the game. This is an aspect that was a little more difficult to implement in Defold than Godot or Gamemaker as they both have this as standard functions. But I have it worked out. And I summarized it in redeck English best I could on the navgo post in this forum. But I will place it here as well for my reference.
Next step is creating my marble wave generator- which would be a factory producing marbles from an array. Which is what I did in Godot and it should work here.
Each map is designed to have 150 levels or waves of marbles increasing in difficulty. AFter wave 5 sentient marbles appear and destroy your towers if not killed first!
So to simplify this whole thread: REDO 2
A. install library for the project as a dependency
B. Then in the collection:
- in collection add go handler
- create a folder in main called: directionalCharacter
3.Add a game obejct called directionalCharacterGo - add a script called directionalCharacterSingleton
- Add this text in directionalCharacterSingleton script:
- Add this text in directionalCharacterSingleton 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)
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
- in outline click on the singleton script and set the start =1 and end = 100 or whatever node qty you might need
- add directional nodes (you can cut and paste as well)
- in direction node script update this node to current node number, and goto node as next node number. Start node: this=1, next= 2 , second node: this=2, next=3 … end this=100 , next=1 . End and start nodes must match script in handler script
- sprite must stay named sprite in the nodes
- From within the collection you have to initialize the NavGo handler by sending an init message. I recommend having the following code in your main script to handle it.
function init(self)
local message = {}
message.collisions = { hash("wall") }
message.debug = false
message.deleteNodeAfterGotten = true
message.nodeNeighborRange = 400
message.nodeNeighborRange = 400
msg.post("/NavGO_HandlerGO#NavGO_HandlerScript", hash("init"), message)
end
function on_message(self, message_id, message, sender)
if message_id == hash("NavGO_Ready") then
-- NavGo is ready to be used
-- Add game start code
end
end
Update got the basic script working for multiple marbles: