Open BrunoMine opened 6 years ago
While in theory it should work, I honestly recommend to you to calculate the yaw and pass it to advanced_npc:rotate
as yaw
argument.
Also, see if pos
has the position argument that you expect.
But assuming I want to rotate to a place that will change in a previous instruction or program. How do I do this?
The problem is in npc.programs.helper.get_pos_argument
3rd argument, true is for acess_node.
I must have mistaken myself for the comments.
-- Return the first position only if it couldn't find an owned
-- place, or if it there is only one
if use_access_node == true then
return places_pos[1].access_node, places_pos[1].pos
else
return places_pos[1].pos
end
Ah got it, yes, that happens.
Regarding the future position, that is a little bit more tricky. That's the purpose of variables, store the position as variable (npc.exec.var.put()
). Register a instruction that does this:
npc.programs.instr.register("future_rotate", function(self, args)
local future_pos = npc.exec.var.get(self, "future_pos")
npc.programs.instr.execute(self, "advanced_npc:rotate", {yaw = minetest.dir_to_yaw(vector.direction(self.object:getpos(), future_pos))})
end
Then enqueue this instruction after the execution of the program/instruction that calculates and stores the pos.
So if I want to reference my future pos I should do.
npc.programs.instr.register("update_my_pos", function(self, args)
npc.exec.var.set(self, "future_pos", self.object:getpos())
end
npc.programs.instr.register("rotate", function(self, args)
local future_pos = npc.exec.var.get(self, "future_pos")
npc.programs.instr.execute(self, "advanced_npc:rotate", {yaw = minetest.dir_to_yaw(vector.direction(self.object:getpos(), future_pos))})
end
npc.programs.register("interact", function(self, args)
local tempo = args.time or 5
local pos = npc.programs.helper.get_pos_argument(self, args.pos, true)
-- Rotate
npc.exec.proc.enqueue(self, "rotate", {})
-- Wait
npc.exec.proc.enqueue(self, "wait", {
time = time,
})
-- Walk to a random pos
npc.exec.proc.enqueue(self, "walk_to_pos", {})
-- Update variable
npc.exec.proc.enqueue(self, "update_my_pos", {})
-- New Rotate
npc.exec.proc.enqueue(self, "advanced_npc:rotate", {})
end)
My example sucks, but I want to say that the variable needs to be updated by another instruction.
Maybe if you tell me your exact use case I can help you figure out how to do it. But in general yes your code should work.
I'm trying to create a program and get this for now.
It looks like the NPC does not rotate to the right place.
I did not understand correctly where the temporary data is and how to reference future places.