Merge pull request #10 from TheTermos/dev2

Dev2
master
TheTermos 2019-11-07 20:50:04 +01:00 committed by GitHub
commit 66800b5c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -17,6 +17,7 @@ local random = math.random
local sqrt = math.sqrt local sqrt = math.sqrt
local max = math.max local max = math.max
local min = math.min local min = math.min
local tan = math.tan
local pow = math.pow local pow = math.pow
local sign = function(x) local sign = function(x)
@ -316,6 +317,12 @@ function mobkit.dir_to_rot(v,rot)
z=rot.z} z=rot.z}
end end
function mobkit.rot_to_dir(rot) -- keep rot within <-pi/2,pi/2>
local dir = minetest.yaw_to_dir(rot.y)
dir.y = dir.y+tan(rot.x)*vector.length(dir)
return vector.normalize(dir)
end
function mobkit.isnear2d(p1,p2,thresh) function mobkit.isnear2d(p1,p2,thresh)
if abs(p2.x-p1.x) < thresh and abs(p2.z-p1.z) < thresh then if abs(p2.x-p1.x) < thresh and abs(p2.z-p1.z) < thresh then
return true return true
@ -815,11 +822,11 @@ function mobkit.physics(self)
end end
if surface then -- standing in liquid if surface then -- standing in liquid
self.isinliquid = true self.isinliquid = true
local submergence = min(surface-spos.y,self.height) local submergence = min(surface-spos.y,self.height)/self.height
local balance = self.buoyancy*self.height -- local balance = self.buoyancy*self.height
local buoyacc = mobkit.gravity*((balance - submergence)^2/balance^2*sign(balance - submergence)) local buoyacc = mobkit.gravity*(self.buoyancy-submergence)
mobkit.set_acceleration(self.object, mobkit.set_acceleration(self.object,
{x=-vel.x*self.water_drag,y=buoyacc-vel.y*abs(vel.y)*0.7,z=-vel.z*self.water_drag}) {x=-vel.x*self.water_drag,y=buoyacc-vel.y*abs(vel.y)*0.4,z=-vel.z*self.water_drag})
else else
self.isinliquid = false self.isinliquid = false
self.object:set_acceleration({x=0,y=mobkit.gravity,z=0}) self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
@ -919,7 +926,8 @@ function mobkit.stepfunc(self,dtime) -- not intended to be modified
local vel = self.object:get_velocity() local vel = self.object:get_velocity()
-- if self.lastvelocity.y == vel.y then -- if self.lastvelocity.y == vel.y then
if abs(self.lastvelocity.y-vel.y)<0.001 then -- if abs(self.lastvelocity.y-vel.y)<0.001 then
if self.lastvelocity.y==0 and vel.y==0 then
self.isonground = true self.isonground = true
else else
self.isonground = false self.isonground = false
@ -934,7 +942,7 @@ function mobkit.stepfunc(self,dtime) -- not intended to be modified
end end
self.lastvelocity = self.object:get_velocity() self.lastvelocity = self.object:get_velocity()
self.time_total=self.time_total+dtime self.time_total=self.time_total+self.dtime
end end
---------------------------- ----------------------------

View File

@ -319,6 +319,9 @@ function mobkit.isnear3d(p1,p2,thresh)
function mobkit.dir_to_rot(v,rot) function mobkit.dir_to_rot(v,rot)
-- converts a 3d vector v to rotation like in set_rotation() object method -- converts a 3d vector v to rotation like in set_rotation() object method
-- rot (optional) is current object rotation -- rot (optional) is current object rotation
function mobkit.rot_to_dir(rot)
-- converts minetest rotation vector (pitch,yaw,roll) to direction unit vector
function mobkit.is_alive(thing) function mobkit.is_alive(thing)
-- non essential, checks if thing exists in the world and is alive -- non essential, checks if thing exists in the world and is alive