mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-11-14 14:30:19 +01:00
add 'homing' setting to mob definition so that arrows can follow player when visible.
This commit is contained in:
parent
d1f23e8ed8
commit
682d76d7b3
26
api.lua
26
api.lua
|
@ -11,7 +11,7 @@ local use_mc2 = minetest.get_modpath("mcl_core")
|
|||
-- Global
|
||||
mobs = {
|
||||
mod = "redo",
|
||||
version = "20231111",
|
||||
version = "20231116",
|
||||
translate = S,
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||
node_snow = minetest.registered_aliases["mapgen_snow"]
|
||||
|
@ -2653,6 +2653,12 @@ function mob_class:do_states(dtime)
|
|||
ent.switch = 1
|
||||
ent.owner_id = tostring(self.object) -- add unique owner id to arrow
|
||||
|
||||
-- setup homing arrow and target
|
||||
if self.homing then
|
||||
ent._target = self.attack
|
||||
ent.homing = true
|
||||
end
|
||||
|
||||
-- offset makes shoot aim accurate
|
||||
vec.y = vec.y + self.shoot_offset
|
||||
vec.x = vec.x * (v / amount)
|
||||
|
@ -3593,6 +3599,7 @@ minetest.register_entity(":" .. name, setmetatable({
|
|||
arrow = def.arrow,
|
||||
arrow_override = def.arrow_override,
|
||||
shoot_interval = def.shoot_interval,
|
||||
homing = def.homing,
|
||||
sounds = def.sounds,
|
||||
animation = def.animation,
|
||||
follow = def.follow,
|
||||
|
@ -4224,6 +4231,23 @@ function mobs:register_arrow(name, def)
|
|||
end
|
||||
end
|
||||
|
||||
-- make homing arrows follow target if seen
|
||||
if self.homing and self._target then
|
||||
|
||||
local p = self._target:get_pos()
|
||||
|
||||
if p then
|
||||
|
||||
if minetest.line_of_sight(self.object:get_pos(), p) then
|
||||
|
||||
self.object:set_velocity(
|
||||
vector.direction(self.object:get_pos(), p) * self.velocity)
|
||||
end
|
||||
else
|
||||
self._target = nil
|
||||
end
|
||||
end
|
||||
|
||||
if self.hit_player or self.hit_mob or self.hit_object then
|
||||
|
||||
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do
|
||||
|
|
3
api.txt
3
api.txt
|
@ -148,8 +148,9 @@ functions needed for the mob to work properly which contains the following:
|
|||
'dogshoot_count2_max' contains how many seconds before switching from shoot
|
||||
to dogfight.
|
||||
'shoot_interval' has the number of seconds between shots.
|
||||
'shoot_offset' holds the y position added as to where the
|
||||
'shoot_offset' holds the y position added as to where the
|
||||
arrow/fireball appears on mob.
|
||||
'homing' When True arrows will follow player when visible.
|
||||
'specific_attack' has a table of entity names that mob can also attack
|
||||
e.g. {"player", "mobs_animal:chicken"}.
|
||||
'friendly_fire` when set to false, mobs will not be able to harm other
|
||||
|
|
Loading…
Reference in New Issue
Block a user