mirror of
https://github.com/APercy/airutils.git
synced 2025-03-21 18:41:21 +00:00
improved bobing and buoyance
This commit is contained in:
parent
08db96a114
commit
39e8fcf71d
2 changed files with 11 additions and 10 deletions
|
@ -24,22 +24,24 @@ function airutils.physics(self)
|
||||||
self.isinliquid = true
|
self.isinliquid = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.object:move_to(self.object:get_pos())
|
||||||
if self.isinliquid then
|
if self.isinliquid then
|
||||||
local accell = {x=0, y=0, z=0}
|
local accell = {x=0, y=0, z=0}
|
||||||
self.water_drag = 0.1
|
self.water_drag = 0.2
|
||||||
|
self.isinliquid = true
|
||||||
local height = self.height
|
local height = self.height
|
||||||
local submergence = math.min(surface-spos.y,height)/height
|
local submergence = math.min(surface-spos.y,height)/height
|
||||||
-- local balance = self.buoyancy*self.height
|
-- local balance = self.buoyancy*self.height
|
||||||
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
|
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
|
||||||
--minetest.chat_send_all(buoyacc)
|
--local buoyacc = self._baloon_buoyancy*(self.buoyancy-submergence)
|
||||||
accell = {x=-new_velocity.x*self.water_drag,y=buoyacc-(new_velocity.y*math.abs(new_velocity.y)*5.4),z=-new_velocity.z*self.water_drag}
|
accell = {x=-vel.x*self.water_drag,y=buoyacc-(vel.y*math.abs(vel.y)*0.4),z=-vel.z*self.water_drag}
|
||||||
|
|
||||||
if self.buoyancy >= 1 then self._engine_running = false end
|
if self.buoyancy >= 1 then self._engine_running = false end
|
||||||
new_velocity = vector.add(new_velocity, vector.multiply(accell, self.dtime))
|
airutils.set_acceleration(self.object,accell)
|
||||||
|
--new_velocity = vector.add(new_velocity, vector.multiply(accell, self.dtime))
|
||||||
else
|
else
|
||||||
airutils.set_acceleration(self.object,{x=0,y=0,z=0})
|
airutils.set_acceleration(self.object,{x=0,y=airutils.gravity,z=0})
|
||||||
self.isinliquid = false
|
self.isinliquid = false
|
||||||
new_velocity = vector.add(new_velocity, {x=0,y=airutils.gravity * self.dtime,z=0})
|
--new_velocity = vector.add(new_velocity, {x=0,y=airutils.gravity * self.dtime,z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.isonground and not self.isinliquid then
|
if self.isonground and not self.isinliquid then
|
||||||
|
@ -69,9 +71,8 @@ function airutils.physics(self)
|
||||||
end
|
end
|
||||||
new_velocity = vnew
|
new_velocity = vnew
|
||||||
end
|
end
|
||||||
|
self.object:set_velocity(new_velocity)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:set_velocity(new_velocity)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -400,7 +400,7 @@ function airutils.logic(self)
|
||||||
|
|
||||||
--lets apply some bob in water
|
--lets apply some bob in water
|
||||||
if self.isinliquid then
|
if self.isinliquid then
|
||||||
local bob = airutils.minmax(airutils.dot(accel,hull_direction),0.5) -- vertical bobbing
|
local bob = airutils.minmax(airutils.dot(accel,hull_direction),0.02) -- vertical bobbing
|
||||||
if bob < 0 then bob = 0 end
|
if bob < 0 then bob = 0 end
|
||||||
accel.y = accel.y + bob
|
accel.y = accel.y + bob
|
||||||
local max_pitch = 6
|
local max_pitch = 6
|
||||||
|
|
Loading…
Add table
Reference in a new issue