Really fix it this time
This commit is contained in:
parent
b3b4e7cd71
commit
1633795ecd
73
api.lua
73
api.lua
@ -250,45 +250,44 @@ function mobs:register_mob(name, def)
|
|||||||
if self.following:get_wielded_item():get_name() ~= self.follow then
|
if self.following:get_wielded_item():get_name() ~= self.follow then
|
||||||
self.following = nil
|
self.following = nil
|
||||||
self.v_start = false
|
self.v_start = false
|
||||||
return
|
|
||||||
end
|
|
||||||
local s = self.object:getpos()
|
|
||||||
local p = self.following:getpos()
|
|
||||||
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
|
|
||||||
if dist > self.view_range then
|
|
||||||
self.following = nil
|
|
||||||
self.v_start = false
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
|
|
||||||
local yaw = math.atan(vec.z/vec.x)+math.pi/2
|
|
||||||
if self.drawtype == "side" then
|
|
||||||
yaw = yaw+(math.pi/2)
|
|
||||||
end
|
|
||||||
if p.x > s.x then
|
|
||||||
yaw = yaw+math.pi
|
|
||||||
end
|
|
||||||
self.object:setyaw(yaw)
|
|
||||||
if dist > 2 then
|
|
||||||
if not self.v_start then
|
|
||||||
self.v_start = true
|
|
||||||
self.set_velocity(self, self.walk_velocity)
|
|
||||||
else
|
|
||||||
if self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
|
|
||||||
local v = self.object:getvelocity()
|
|
||||||
v.y = 5
|
|
||||||
self.object:setvelocity(v)
|
|
||||||
end
|
|
||||||
self.set_velocity(self, self.walk_velocity)
|
|
||||||
end
|
|
||||||
self:set_animation("walk")
|
|
||||||
else
|
else
|
||||||
self.v_start = false
|
local s = self.object:getpos()
|
||||||
self.set_velocity(self, 0)
|
local p = self.following:getpos()
|
||||||
self:set_animation("stand")
|
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
|
||||||
|
if dist > self.view_range then
|
||||||
|
self.following = nil
|
||||||
|
self.v_start = false
|
||||||
|
else
|
||||||
|
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
|
||||||
|
local yaw = math.atan(vec.z/vec.x)+math.pi/2
|
||||||
|
if self.drawtype == "side" then
|
||||||
|
yaw = yaw+(math.pi/2)
|
||||||
|
end
|
||||||
|
if p.x > s.x then
|
||||||
|
yaw = yaw+math.pi
|
||||||
|
end
|
||||||
|
self.object:setyaw(yaw)
|
||||||
|
if dist > 2 then
|
||||||
|
if not self.v_start then
|
||||||
|
self.v_start = true
|
||||||
|
self.set_velocity(self, self.walk_velocity)
|
||||||
|
else
|
||||||
|
if self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
|
||||||
|
local v = self.object:getvelocity()
|
||||||
|
v.y = 5
|
||||||
|
self.object:setvelocity(v)
|
||||||
|
end
|
||||||
|
self.set_velocity(self, self.walk_velocity)
|
||||||
|
end
|
||||||
|
self:set_animation("walk")
|
||||||
|
else
|
||||||
|
self.v_start = false
|
||||||
|
self.set_velocity(self, 0)
|
||||||
|
self:set_animation("stand")
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user