diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2018-09-15 10:20:18 +0100 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2018-09-15 10:20:18 +0100 |
commit | afb7e01b918874b48fe7281166136c87d283d66c (patch) | |
tree | f93a3cfcf64897d981592aa837c957c8fb4ca308 | |
parent | 830b1698ffa75c16345096b20a2b52e0276d2e5d (diff) |
tweak collision functionmob_api_21sep2018
-rw-r--r-- | api.lua | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20180914", + version = "20180915", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {}, } @@ -108,32 +108,37 @@ local do_attack = function(self, player) 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 pos = self.object:get_pos() local vel = self.object:get_velocity() - local x = 0 - local z = 0 + local x, z = 0, 0 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() or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then local pos2 = object:get_pos() 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) - z = z + (vec.z * force) + x = x + vec.x + z = z + vec.z end end - return({x,z}) + return({x, z}) end @@ -250,15 +255,6 @@ function mobs:set_animation(self, anim) 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) local line_of_sight = function(self, pos1, pos2, stepsize) |