Make boats return to their first position
parent
d423e28977
commit
8d1f2d3b55
16
init.lua
16
init.lua
|
@ -186,19 +186,23 @@ function boat.selfdriving_step(self, dtime)
|
||||||
local instr = self.instructions[1]
|
local instr = self.instructions[1]
|
||||||
local curpos = self.get_instr_pos(instr)
|
local curpos = self.get_instr_pos(instr)
|
||||||
self.object:setpos(curpos)
|
self.object:setpos(curpos)
|
||||||
self.dnext = -1
|
local nextpos = self.instructions[self.current+1]
|
||||||
local nextpos = self.instructions[self.current+2]
|
|
||||||
nextpos = self.get_instr_pos(nextpos)
|
nextpos = self.get_instr_pos(nextpos)
|
||||||
self.object:setpos(nextpos)
|
self.object:setpos(curpos)
|
||||||
self.object:setyaw(math.pi/4*instr[4])
|
self.object:setyaw(core.dir_to_yaw(vector.direction(curpos,nextpos)))
|
||||||
self.v = instr[5]
|
self.v = instr[5]
|
||||||
self.dnext = vector.distance(curpos,nextpos)
|
self.dnext = vector.distance(curpos,nextpos)
|
||||||
end
|
end
|
||||||
if self.dnext < 0 then
|
if self.dnext < 0 then
|
||||||
self.current = self.current + 1
|
self.current = self.current + 1
|
||||||
if self.current == #self.instructions then
|
if self.current == #self.instructions then
|
||||||
self.selfdriving = false
|
local instr = self.instructions[self.current]
|
||||||
self.v = 0
|
self.current = 0
|
||||||
|
local nextpos = self.instructions[1]
|
||||||
|
nextpos = self.get_instr_pos(nextpos)
|
||||||
|
local curpos = self.get_instr_pos(instr)
|
||||||
|
self.object:setyaw(core.dir_to_yaw(vector.direction(curpos,nextpos)))
|
||||||
|
self.dnext = vector.distance(curpos,nextpos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue