From 39e8fcf71d4f2b312c0518d3725780122cd4c000 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Mon, 17 Jul 2023 04:55:29 -0300 Subject: [PATCH] improved bobing and buoyance --- lib_planes/custom_physics.lua | 19 ++++++++++--------- lib_planes/entities.lua | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib_planes/custom_physics.lua b/lib_planes/custom_physics.lua index 7e369e1..50f6405 100755 --- a/lib_planes/custom_physics.lua +++ b/lib_planes/custom_physics.lua @@ -24,22 +24,24 @@ function airutils.physics(self) self.isinliquid = true end + self.object:move_to(self.object:get_pos()) if self.isinliquid then 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 submergence = math.min(surface-spos.y,height)/height -- local balance = self.buoyancy*self.height local buoyacc = airutils.gravity*(self.buoyancy-submergence) - --minetest.chat_send_all(buoyacc) - 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} - + --local buoyacc = self._baloon_buoyancy*(self.buoyancy-submergence) + 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 - 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 - 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 - 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 if self.isonground and not self.isinliquid then @@ -69,9 +71,8 @@ function airutils.physics(self) end new_velocity = vnew end + self.object:set_velocity(new_velocity) end - self.object:set_velocity(new_velocity) - end diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 37b6509..0826a99 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -400,7 +400,7 @@ function airutils.logic(self) --lets apply some bob in water 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 accel.y = accel.y + bob local max_pitch = 6