fix:when player is in attack range stop followin path and reset stuck timer to 0 so attack can begin immidiately
This commit is contained in:
parent
c5de3d73f8
commit
29ce96593e
8
api.lua
8
api.lua
@ -1441,11 +1441,12 @@ minetest.register_entity(name, {
|
|||||||
-- rnd: new movement direction
|
-- rnd: new movement direction
|
||||||
|
|
||||||
if self.path.stuck and self.path.way then
|
if self.path.stuck and self.path.way then
|
||||||
if #self.path.way>50 then self.path.stuck = false return end -- no paths longer than 50
|
if #self.path.way>50 or dist<self.reach then self.path.stuck = false return end -- no paths longer than 50
|
||||||
local p1 = self.path.way[1]; if not p1 then self.path.stuck = false return end
|
local p1 = self.path.way[1]; if not p1 then self.path.stuck = false return end
|
||||||
if math.abs(p1.x-s.x)+math.abs(p1.z-s.z)<0.6 then -- reached waypoint, remove it from queue
|
if math.abs(p1.x-s.x)+math.abs(p1.z-s.z)<0.6 then -- reached waypoint, remove it from queue
|
||||||
table.remove(self.path.way,1);
|
table.remove(self.path.way,1);
|
||||||
end
|
end
|
||||||
|
|
||||||
p = {x=p1.x,y=p1.y,z=p1.z}; -- set new temporary target
|
p = {x=p1.x,y=p1.y,z=p1.z}; -- set new temporary target
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1473,7 +1474,7 @@ minetest.register_entity(name, {
|
|||||||
-- PATH FINDING by rnd
|
-- PATH FINDING by rnd
|
||||||
if enable_pathfinding then
|
if enable_pathfinding then
|
||||||
local s1 = self.path.lastpos;
|
local s1 = self.path.lastpos;
|
||||||
if math.abs(s1.x-s.x)+math.abs(s1.z-s.z)<1. then -- is it becoming stuck?
|
if math.abs(s1.x-s.x)+math.abs(s1.z-s.z)<1.5 then -- is it becoming stuck?
|
||||||
self.path.stuck_timer = self.path.stuck_timer+dtime
|
self.path.stuck_timer = self.path.stuck_timer+dtime
|
||||||
else self.path.stuck_timer = 0;
|
else self.path.stuck_timer = 0;
|
||||||
end
|
end
|
||||||
@ -1553,6 +1554,7 @@ minetest.register_entity(name, {
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
self.path.stuck = false; -- rnd: no more stuck
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
set_animation(self, "punch")
|
set_animation(self, "punch")
|
||||||
|
|
||||||
@ -1577,7 +1579,6 @@ minetest.register_entity(name, {
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
self.path.stuck = false; -- rnd: no more stuck
|
|
||||||
|
|
||||||
-- punch player
|
-- punch player
|
||||||
self.attack:punch(self.object, 1.0, {
|
self.attack:punch(self.object, 1.0, {
|
||||||
@ -1755,6 +1756,7 @@ minetest.register_entity(name, {
|
|||||||
and hitter:get_player_name() ~= self.owner then
|
and hitter:get_player_name() ~= self.owner then
|
||||||
|
|
||||||
if self.state ~= "attack" then
|
if self.state ~= "attack" then
|
||||||
|
self.path.stuck=false; -- dont follow path anymore
|
||||||
do_attack(self, hitter)
|
do_attack(self, hitter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user