Add an option for mob arrows to be "homing"
parent
b4511fb8c7
commit
f5079f1568
|
@ -1231,6 +1231,9 @@ function mob_class:do_states_attack (dtime)
|
||||||
-- important for mcl_shields
|
-- important for mcl_shields
|
||||||
ent._shooter = self.object
|
ent._shooter = self.object
|
||||||
ent._saved_shooter_pos = self.object:get_pos()
|
ent._saved_shooter_pos = self.object:get_pos()
|
||||||
|
if ent.homing then
|
||||||
|
ent._target = self.attack
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5
|
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5
|
||||||
|
|
|
@ -350,6 +350,7 @@ function mcl_mobs.register_arrow(name, def)
|
||||||
hit_node = def.hit_node,
|
hit_node = def.hit_node,
|
||||||
hit_mob = def.hit_mob,
|
hit_mob = def.hit_mob,
|
||||||
hit_object = def.hit_object,
|
hit_object = def.hit_object,
|
||||||
|
homing = def.homing,
|
||||||
drop = def.drop or false, -- drops arrow as registered item when true
|
drop = def.drop or false, -- drops arrow as registered item when true
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows
|
collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows
|
||||||
timer = 0,
|
timer = 0,
|
||||||
|
@ -422,6 +423,17 @@ function mcl_mobs.register_arrow(name, def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
if self.hit_player or self.hit_mob or self.hit_object then
|
||||||
|
|
||||||
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
|
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
|
||||||
|
|
Loading…
Reference in New Issue