Tweak cod

This commit is contained in:
epCode 2021-03-30 14:52:46 -07:00
parent 85dccd50c7
commit 36a24c6c07
2 changed files with 39 additions and 0 deletions

39
cod.lua
View File

@ -3,6 +3,26 @@
--made for MC like Survival game --made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes --License for code WTFPL and otherwise stated in readmes
local pi = math.pi
local atann = math.atan
local atan = function(x)
if not x or x ~= x then
return 0
else
return atann(x)
end
end
local dir_to_pitch = function(dir)
local dir2 = vector.normalize(dir)
local xz = math.abs(dir.x) + math.abs(dir.z)
return -math.atan2(-dir.y, xz)
end
local function degrees(rad)
return rad * 180.0 / math.pi
end
local S = minetest.get_translator("extra_mobs") local S = minetest.get_translator("extra_mobs")
--################### --###################
@ -56,6 +76,25 @@ local cod = {
view_range = 16, view_range = 16,
runaway = true, runaway = true,
fear_height = 4, fear_height = 4,
do_custom = function(self)
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
self.object:add_velocity({ x = 0 , y = math.random(-.05, .05) , z = 0 })
end
for _,object in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 10)) do
local lp = object:get_pos()
local s = self.object:get_pos()
local vec = {
x = lp.x - s.x,
y = lp.y - s.y,
z = lp.z - s.z
}
if not object:is_player() and object:get_luaentity().name == "extra_mobs:cod" then
self.state = "runaway"
self.object:set_rotation({x=0,y=(atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate,z=0})
end
end
end
} }
mobs:register_mob("extra_mobs:cod", cod) mobs:register_mob("extra_mobs:cod", cod)

Binary file not shown.