summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2018-09-14 17:13:40 +0100
committerTenPlus1 <kinsellaja@yahoo.com>2018-09-14 17:13:40 +0100
commit830b1698ffa75c16345096b20a2b52e0276d2e5d (patch)
treef957d24664ad5b3ed8756c8d87bfd0eb666f445d
parent82411330fcab88333a866fe5fd5a58ffe196f4b1 (diff)
added pushable flag for mobs so they can be pushed by player
-rw-r--r--api.lua43
-rw-r--r--api.txt1
2 files changed, 41 insertions, 3 deletions
diff --git a/api.lua b/api.lua
index 79b178d..17b3b11 100644
--- a/api.lua
+++ b/api.lua
@@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
- version = "20180909",
+ version = "20180914",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {},
}
@@ -108,9 +108,45 @@ local do_attack = function(self, player)
end
+-- collision function borrowed amended 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 width = -self.collisionbox[1] + self.collisionbox[4] + 0.5
+
+ for _,object in ipairs(minetest.env: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)
+ end
+ end
+
+ return({x,z})
+end
+
+
-- move mob in facing direction
local set_velocity = function(self, v)
+ local c_x, c_y = 0, 0
+
+ -- can mob be pushed, if so calculate direction
+ if self.pushable then
+ c_x, c_y = unpack(collision(self))
+ end
+
-- halt mob if it has been ordered to stay
if self.order == "stand" then
self.object:set_velocity({x = 0, y = 0, z = 0})
@@ -120,9 +156,9 @@ local set_velocity = function(self, v)
local yaw = (self.object:get_yaw() or 0) + self.rotate
self.object:set_velocity({
- x = sin(yaw) * -v,
+ x = (sin(yaw) * -v) + c_x,
y = self.object:get_velocity().y,
- z = cos(yaw) * v
+ z = (cos(yaw) * v) + c_y,
})
end
@@ -3049,6 +3085,7 @@ minetest.register_entity(name, {
runaway_from = def.runaway_from,
owner_loyal = def.owner_loyal,
facing_fence = false,
+ pushable = def.pushable,
_cmi_is_mob = true,
on_spawn = def.on_spawn,
diff --git a/api.txt b/api.txt
index 8e3fdd0..126de42 100644
--- a/api.txt
+++ b/api.txt
@@ -45,6 +45,7 @@ functions needed for the mob to work properly which contains the following:
'fly_in' holds the node name that the mob flies (or swims) around
in e.g. "air" or "default:water_source".
'runaway' if true causes animals to turn and run away when hit.
+ 'pushable' when true mobs can be pushed by player or other mobs.
'view_range' how many nodes in distance the mob can see a player.
'damage' how many health points the mob does to a player or another
mob when melee attacking.