Add files via upload
parent
b4fed07fca
commit
9f7cb196e2
45
init.lua
45
init.lua
|
@ -54,7 +54,7 @@ function mobkit.neighbor_shift(neighbor,shift) -- int shift: minus is left, plus
|
||||||
return (8+neighbor+shift-1)%8+1
|
return (8+neighbor+shift-1)%8+1
|
||||||
end
|
end
|
||||||
|
|
||||||
function mobkit.pos_shift(pos,vec)
|
function mobkit.pos_shift(pos,vec) -- vec components can be omitted e.g. vec={y=1}
|
||||||
vec.x=vec.x or 0
|
vec.x=vec.x or 0
|
||||||
vec.y=vec.y or 0
|
vec.y=vec.y or 0
|
||||||
vec.z=vec.z or 0
|
vec.z=vec.z or 0
|
||||||
|
@ -63,7 +63,18 @@ function mobkit.pos_shift(pos,vec)
|
||||||
z=pos.z+vec.z}
|
z=pos.z+vec.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mobkit.pos_translate2d(pos,yaw,dist) -- translate pos dist distance in yaw direction
|
||||||
|
return vector.add(pos,vector.multiply(minetest.yaw_to_dir(yaw),dist))
|
||||||
|
end
|
||||||
|
|
||||||
|
function mobkit.is_pos_in_box(pos,bpos,box)
|
||||||
|
return pos.x > bpos.x+box[1] and pos.x < bpos.x+box[4] and
|
||||||
|
pos.y > bpos.y+box[2] and pos.y < bpos.y+box[5] and
|
||||||
|
pos.z > bpos.z+box[3] and pos.z < bpos.z+box[6]
|
||||||
|
end
|
||||||
|
|
||||||
-- call this instead if you want feet position.
|
-- call this instead if you want feet position.
|
||||||
|
--[[
|
||||||
function mobkit.get_stand_pos(thing) -- thing can be luaentity or objectref.
|
function mobkit.get_stand_pos(thing) -- thing can be luaentity or objectref.
|
||||||
if type(thing) == 'table' then
|
if type(thing) == 'table' then
|
||||||
return mobkit.pos_shift(thing.object:get_pos(),{y=thing.collisionbox[2]+0.01})
|
return mobkit.pos_shift(thing.object:get_pos(),{y=thing.collisionbox[2]+0.01})
|
||||||
|
@ -71,6 +82,21 @@ function mobkit.get_stand_pos(thing) -- thing can be luaentity or objectref.
|
||||||
local colbox = thing:get_properties().collisionbox
|
local colbox = thing:get_properties().collisionbox
|
||||||
return mobkit.pos_shift(thing:get_pos(),{y=colbox[2]+0.01})
|
return mobkit.pos_shift(thing:get_pos(),{y=colbox[2]+0.01})
|
||||||
end
|
end
|
||||||
|
end --]]
|
||||||
|
|
||||||
|
function mobkit.get_stand_pos(thing) -- thing can be luaentity or objectref.
|
||||||
|
local pos = {}
|
||||||
|
local colbox = {}
|
||||||
|
if type(thing) == 'table' then
|
||||||
|
pos = thing.object:get_pos()
|
||||||
|
colbox = thing.collisionbox
|
||||||
|
elseif type(thing) == 'userdata' then
|
||||||
|
pos = thing:get_pos()
|
||||||
|
colbox = thing:get_properties().collisionbox
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return mobkit.pos_shift(pos,{y=colbox[2]+0.01}), pos
|
||||||
end
|
end
|
||||||
|
|
||||||
function mobkit.nodeatpos(pos)
|
function mobkit.nodeatpos(pos)
|
||||||
|
@ -1416,12 +1442,11 @@ function mobkit.hq_aqua_roam(self,prty,speed)
|
||||||
end
|
end
|
||||||
local pos = mobkit.get_stand_pos(self)
|
local pos = mobkit.get_stand_pos(self)
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
local pos2d = {x=pos.x,y=0,z=pos.z}
|
local scanpos = mobkit.get_node_pos(mobkit.pos_translate2d(pos,yaw,speed))
|
||||||
local scanpos = mobkit.get_node_pos(vector.add(pos,vector.multiply(minetest.yaw_to_dir(yaw),speed)))
|
|
||||||
if not vector.equals(prvscanpos,scanpos) then
|
if not vector.equals(prvscanpos,scanpos) then
|
||||||
prvscanpos=scanpos
|
prvscanpos=scanpos
|
||||||
local nyaw,height = aqua_radar_dumb(pos,yaw,speed,true)
|
local nyaw,height = aqua_radar_dumb(pos,yaw,speed,true)
|
||||||
if height and height > pos.y+self.collisionbox[2] then
|
if height and height > pos.y then
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
vel.y = vel.y+1
|
vel.y = vel.y+1
|
||||||
self.object:set_velocity(vel)
|
self.object:set_velocity(vel)
|
||||||
|
@ -1442,7 +1467,7 @@ function mobkit.hq_aqua_roam(self,prty,speed)
|
||||||
|
|
||||||
mobkit.turn2yaw(self,tyaw,3)
|
mobkit.turn2yaw(self,tyaw,3)
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
mobkit.go_forward_horizontal(self,yaw,4)
|
mobkit.go_forward_horizontal(self,yaw,speed)
|
||||||
end
|
end
|
||||||
mobkit.queue_high(self,func,prty)
|
mobkit.queue_high(self,func,prty)
|
||||||
end
|
end
|
||||||
|
@ -1461,6 +1486,7 @@ function mobkit.hq_aqua_attack(self,prty,tgtobj,speed)
|
||||||
local tyaw = 0
|
local tyaw = 0
|
||||||
local prvscanpos = {x=0,y=0,z=0}
|
local prvscanpos = {x=0,y=0,z=0}
|
||||||
local init = true
|
local init = true
|
||||||
|
local tgtbox = tgtobj:get_properties().collisionbox
|
||||||
local func = function(self)
|
local func = function(self)
|
||||||
if not mobkit.is_alive(tgtobj) then return true end
|
if not mobkit.is_alive(tgtobj) then return true end
|
||||||
if init then
|
if init then
|
||||||
|
@ -1470,12 +1496,11 @@ function mobkit.hq_aqua_attack(self,prty,tgtobj,speed)
|
||||||
end
|
end
|
||||||
local pos = mobkit.get_stand_pos(self)
|
local pos = mobkit.get_stand_pos(self)
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
local pos2d = {x=pos.x,y=0,z=pos.z}
|
local scanpos = mobkit.get_node_pos(mobkit.pos_translate2d(pos,yaw,speed))
|
||||||
local scanpos = mobkit.get_node_pos(vector.add(pos,vector.multiply(minetest.yaw_to_dir(yaw),speed)))
|
|
||||||
if not vector.equals(prvscanpos,scanpos) then
|
if not vector.equals(prvscanpos,scanpos) then
|
||||||
prvscanpos=scanpos
|
prvscanpos=scanpos
|
||||||
local nyaw,height = aqua_radar_dumb(pos,yaw,speed)
|
local nyaw,height = aqua_radar_dumb(pos,yaw,speed*0.5)
|
||||||
if height and height > pos.y+self.collisionbox[2] then
|
if height and height > pos.y then
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
vel.y = vel.y+1
|
vel.y = vel.y+1
|
||||||
self.object:set_velocity(vel)
|
self.object:set_velocity(vel)
|
||||||
|
@ -1497,7 +1522,7 @@ function mobkit.hq_aqua_attack(self,prty,tgtobj,speed)
|
||||||
if tpos.y>pos.y+0.5 then self.object:set_velocity({x=vel.x,y=vel.y+0.5,z=vel.z})
|
if tpos.y>pos.y+0.5 then self.object:set_velocity({x=vel.x,y=vel.y+0.5,z=vel.z})
|
||||||
elseif tpos.y<pos.y-0.5 then self.object:set_velocity({x=vel.x,y=vel.y-0.5,z=vel.z}) end
|
elseif tpos.y<pos.y-0.5 then self.object:set_velocity({x=vel.x,y=vel.y-0.5,z=vel.z}) end
|
||||||
end
|
end
|
||||||
if mobkit.isnear3d(mobkit.pos_shift(pos,vector.multiply(minetest.yaw_to_dir(yaw),0.7)),tpos,0.35) then --bite
|
if mobkit.is_pos_in_box(mobkit.pos_translate2d(pos,yaw,self.attack.range),tpos,tgtbox) then --bite
|
||||||
tgtobj:punch(self.object,1,self.attack)
|
tgtobj:punch(self.object,1,self.attack)
|
||||||
mobkit.hq_aqua_turn(self,prty,yaw-pi,speed)
|
mobkit.hq_aqua_turn(self,prty,yaw-pi,speed)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue