1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-26 02:30:21 +01:00

added pushable flag for mobs so they can be pushed by player

This commit is contained in:
TenPlus1 2018-09-14 17:13:40 +01:00
parent 82411330fc
commit 830b1698ff
2 changed files with 41 additions and 3 deletions

43
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20180909", version = "20180914",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}, invis = minetest.global_exists("invisibility") and invisibility or {},
} }
@ -108,9 +108,45 @@ local do_attack = function(self, player)
end 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 -- move mob in facing direction
local set_velocity = function(self, v) 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 -- halt mob if it has been ordered to stay
if self.order == "stand" then if self.order == "stand" then
self.object:set_velocity({x = 0, y = 0, z = 0}) 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 local yaw = (self.object:get_yaw() or 0) + self.rotate
self.object:set_velocity({ self.object:set_velocity({
x = sin(yaw) * -v, x = (sin(yaw) * -v) + c_x,
y = self.object:get_velocity().y, y = self.object:get_velocity().y,
z = cos(yaw) * v z = (cos(yaw) * v) + c_y,
}) })
end end
@ -3049,6 +3085,7 @@ minetest.register_entity(name, {
runaway_from = def.runaway_from, runaway_from = def.runaway_from,
owner_loyal = def.owner_loyal, owner_loyal = def.owner_loyal,
facing_fence = false, facing_fence = false,
pushable = def.pushable,
_cmi_is_mob = true, _cmi_is_mob = true,
on_spawn = def.on_spawn, on_spawn = def.on_spawn,

View File

@ -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 'fly_in' holds the node name that the mob flies (or swims) around
in e.g. "air" or "default:water_source". in e.g. "air" or "default:water_source".
'runaway' if true causes animals to turn and run away when hit. '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. '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 'damage' how many health points the mob does to a player or another
mob when melee attacking. mob when melee attacking.