Merge pull request #5 from TheTermos/dev2

Dev2
master
TheTermos 2019-10-15 12:02:50 +02:00 committed by GitHub
commit 2cd40aa4ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 10 deletions

View File

@ -41,6 +41,10 @@ local neighbors ={
-- UTILITY FUNCTIONS
function mobkit.dot(v1,v2)
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
end
function mobkit.dir2neighbor(dir)
dir.y=0
dir=vector.round(vector.normalize(dir))
@ -285,8 +289,8 @@ function mobkit.turn2yaw(self,tyaw,rate)
local nyaw = (yaw+step*dir)%(pi*2)
self.object:set_yaw(nyaw-pi)
if nyaw==tyaw then return true
else return false end
if nyaw==tyaw then return true, nyaw-pi
else return false, nyaw-pi end
end
function mobkit.dir_to_rot(v,rot)
@ -571,13 +575,24 @@ function mobkit.goto_next_waypoint(self,tpos)
return true
end
function mobkit.go_forward_horizontal(self,yaw,speed) -- sets velocity in yaw direction, y component unaffected
function mobkit.go_forward_horizontal(self,speed) -- sets velocity in yaw direction, y component unaffected
local y = self.object:get_velocity().y
local yaw = self.object:get_yaw()
local vel = vector.multiply(minetest.yaw_to_dir(yaw),speed)
vel.y = y
self.object:set_velocity(vel)
end
function mobkit.drive_to_pos(self,tpos,speed,turn_rate,dist)
local pos=self.object:get_pos()
dist = dist or 0.2
if mobkit.isnear2d(pos,tpos,dist) then return true end
local tyaw = minetest.dir_to_yaw(vector.direction(pos,tpos))
mobkit.turn2yaw(self,tyaw,turn_rate)
mobkit.go_forward_horizontal(self,speed)
return false
end
function mobkit.timer(self,s) -- returns true approx every s seconds
local t1 = floor(self.time_total)
local t2 = floor(self.time_total+self.dtime)
@ -1469,8 +1484,8 @@ function mobkit.hq_aqua_roam(self,prty,speed)
end
mobkit.turn2yaw(self,tyaw,3)
local yaw = self.object:get_yaw()
mobkit.go_forward_horizontal(self,yaw,speed)
-- local yaw = self.object:get_yaw()
mobkit.go_forward_horizontal(self,speed)
end
mobkit.queue_high(self,func,prty)
end
@ -1478,8 +1493,8 @@ end
function mobkit.hq_aqua_turn(self,prty,tyaw,speed)
local func = function(self)
local finished=mobkit.turn2yaw(self,tyaw)
local yaw = self.object:get_yaw()
mobkit.go_forward_horizontal(self,yaw,speed)
-- local yaw = self.object:get_yaw()
mobkit.go_forward_horizontal(self,speed)
if finished then return true end
end
mobkit.queue_high(self,func,prty)
@ -1530,7 +1545,7 @@ function mobkit.hq_aqua_attack(self,prty,tgtobj,speed)
mobkit.hq_aqua_turn(self,prty,yaw-pi,speed)
return true
end
mobkit.go_forward_horizontal(self,yaw,speed)
mobkit.go_forward_horizontal(self,speed)
end
mobkit.queue_high(self,func,prty)
end

View File

@ -241,6 +241,13 @@ function mobkit.get_terrain_height(pos,steps)
-- surface height at pos, or nil if not found
-- liquid flag: true if found surface is covered with liquid
function mobkit.turn2yaw(self,tyaw,rate)
-- gradually turns towards yaw
-- self: luaentity
-- tyaw: target yaw in radians
-- rate: turn rate in rads/s
--returns: true if facing tyaw; current yaw
function mobkit.timer(self,s)
-- returns true approx every s seconds
-- used to reduce execution of code that needn't necessarily be done on every engine step
@ -326,9 +333,15 @@ function mobkit.make_sound(self,sound)
-- sound is string, see entity definition
-- makes an entity play sound, or does nothing if not defined
function mobkit.go_forward_horizontal(self,yaw,speed)
function mobkit.go_forward_horizontal(self,speed)
-- sets an entity's horizontal velocity in yaw direction. Vertical velocity unaffected.
function mobkit.drive_to_pos(self,tpos,speed,turn_rate,dist)
-- moves in facing direction while gradually turning towards tpos, returns true if in dist distance from tpos
-- tpos: target position
-- speed: in m/s
-- turn_rate: in rad/s
-- dist: in m.
-- Memory functions.