mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Add an option for mob arrows to be "homing"
This commit is contained in:
parent
b4511fb8c7
commit
f5079f1568
2 changed files with 15 additions and 0 deletions
|
@ -1231,6 +1231,9 @@ function mob_class:do_states_attack (dtime)
|
|||
-- important for mcl_shields
|
||||
ent._shooter = self.object
|
||||
ent._saved_shooter_pos = self.object:get_pos()
|
||||
if ent.homing then
|
||||
ent._target = self.attack
|
||||
end
|
||||
end
|
||||
|
||||
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_mob = def.hit_mob,
|
||||
hit_object = def.hit_object,
|
||||
homing = def.homing,
|
||||
drop = def.drop or false, -- drops arrow as registered item when true
|
||||
collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows
|
||||
timer = 0,
|
||||
|
@ -422,6 +423,17 @@ function mcl_mobs.register_arrow(name, def)
|
|||
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
|
||||
|
||||
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
|
||||
|
|
Loading…
Reference in a new issue