forked from mtcontrib/mobs_redo
tweak collision function
This commit is contained in:
parent
830b1698ff
commit
afb7e01b91
36
api.lua
36
api.lua
@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20180914",
|
version = "20180915",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
}
|
}
|
||||||
@ -108,32 +108,37 @@ local do_attack = function(self, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- collision function borrowed amended from jordan4ibanez open_ai mod
|
-- calculate distance
|
||||||
|
local get_distance = function(a, b)
|
||||||
|
|
||||||
|
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
|
||||||
|
|
||||||
|
return square(x * x + y * y + z * z)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- collision function based on similar from jordan4ibanez' open_ai mod
|
||||||
local collision = function(self)
|
local collision = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
local x = 0
|
local x, z = 0, 0
|
||||||
local z = 0
|
|
||||||
local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5
|
local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5
|
||||||
|
|
||||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, width)) do
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do
|
||||||
|
|
||||||
if object:is_player()
|
if object:is_player()
|
||||||
or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then
|
or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then
|
||||||
|
|
||||||
local pos2 = object:get_pos()
|
local pos2 = object:get_pos()
|
||||||
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
||||||
local force = (width + 0.5) - vector.distance(
|
|
||||||
{x = pos.x, y = 0, z = pos.z},
|
|
||||||
{x = pos2.x, y = 0, z = pos2.z})
|
|
||||||
|
|
||||||
x = x + (vec.x * force)
|
x = x + vec.x
|
||||||
z = z + (vec.z * force)
|
z = z + vec.z
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return({x,z})
|
return({x, z})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -250,15 +255,6 @@ function mobs:set_animation(self, anim)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- calculate distance
|
|
||||||
local get_distance = function(a, b)
|
|
||||||
|
|
||||||
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
|
|
||||||
|
|
||||||
return square(x * x + y * y + z * z)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- check line of sight (by BrunoMine, tweaked by Astrobe)
|
-- check line of sight (by BrunoMine, tweaked by Astrobe)
|
||||||
local line_of_sight = function(self, pos1, pos2, stepsize)
|
local line_of_sight = function(self, pos1, pos2, stepsize)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user