Okay I remade the project all objects spawn and move.
-- enemy definition
local YELLOW = {
sprite_id = hash("yellowsprite"),
health = 10,
speed = 100,
}
-- enemy definition
local RED = {
sprite_id = hash("redsprite"),
health = 100,
speed = 10,
}
-- enemy definition
local BLUE = {
sprite_id = hash("bluesprite"),
health = 100,
speed = 10,
}
-- enemy definition
local GREEN = {
sprite_id = hash("greensprite"),
health = 100,
speed = 10,
}
function init(self)
-- enemies to spawn
self.enemies = {
YELLOW,
BLUE,
YELLOW,
GREEN,
RED
}
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)
-- get the next enemy to spawn
local enemy = table.remove(self.enemies)
if enemy then
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
--for key, val in pairs(enemy) do
--properties[key] = val --this adds the tables from enemy to the properties variable for factory.create
--end
factory.create(url, position, rotation, properties, scale)
end
)
end
end
But if I add this:
for key, val in pairs(enemy) do
properties[key] = val --this adds the tables from enemy to the properties variable for factory.create
end
to add the sprite_id etc then no objects render.
obj script:
require("navGo_pathfinding.NavGO_Global")
go.property("Start_path_ID", -1)
go.property("End_path_ID", -1)
go.property("speed", 400)
go.property("sprite_id", hash(""))
go.property("health", 100)
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())
print("Number of nodes in path" .. tostring(#path))
for i=1, #path do
local newPosition = vmath.vector3(path[i].x, path[i].y, 0)
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)
print("is calling go.animate")
lastPos = newPosition
delay = delay + time
end
--timer.delay(delay, false, moveCharacter)
end
end
------------------
--Core functions--
------------------
function init(self)
sprite.play_flipbook("#sprite", self.sprite_id)
print(self.health)
print(self.speed)
print("sprite:")
print(self.sprite_id)
timer.delay(1, false, moveCharacter)
print("start")
print(self.Start_path_ID)
print("end")
print(self.End_path_ID)
end