Currently I’m trying to make a simple ai that moves to random locations. I’m confused as to why my self.ai_target_position
variable is nil even though I don’t have typos and I made sure to place the functions in the correct order? (Also I just realised I did the math wrong for the ai movement I’m pretty sure (position + direction * speed * dt) but I got the direction wrong.)
local function random_position()
return vmath.vector3(math.random(1, sys.get_config("display.width")), math.random(1, sys.get_config("display.height")), 0)
end
function init(self)
-- should return a vector
self.ai_target_position = random_position()
end
function fixed_update(self, dt)
ai_pos = go.get_position("/kid")
go.set_position(ai_pos + vmath.vector3(self.ai_target_position.x - ai_pos.x, self.ai_target_position.y - ai_pos.y, 0) * 150 * dt, "/kid")
end
Thanks to anyone who answers.