diff --git a/lib_planes/custom_physics.lua b/lib_planes/custom_physics.lua index eec787d..66cf91a 100755 --- a/lib_planes/custom_physics.lua +++ b/lib_planes/custom_physics.lua @@ -1,7 +1,7 @@ function airutils.physics(self) local friction = self._ground_friction or 0.99 local vel=self.object:get_velocity() - local new_velocity = vel + local new_velocity = vector.new() --buoyancy local surface = nil @@ -24,6 +24,7 @@ function airutils.physics(self) if surface then -- standing in liquid self.isinliquid = true end + local last_accel = self._last_accel if self.isinliquid then local accell = {x=0, y=0, z=0} @@ -37,14 +38,22 @@ function airutils.physics(self) --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 - airutils.set_acceleration(self.object,accell) - --new_velocity = vector.add(new_velocity, vector.multiply(accell, self.dtime)) - self.object:move_to(self.object:get_pos()) - return + if last_accel then + accell = vector.add(accell,last_accel) + end + new_velocity = vector.multiply(accell,self.dtime) + --airutils.set_acceleration(self.object,accell) + --self.object:move_to(self.object:get_pos()) else --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}) + + if self._last_accel then + last_accel.y = last_accel.y + airutils.gravity --gravity here + + new_velocity = vector.multiply(last_accel,self.dtime) + end + --self.object:set_acceleration({x=0,y=new_accel.y, z=0}) end if self.isonground and not self.isinliquid then @@ -85,10 +94,10 @@ function airutils.physics(self) end --self.object:set_velocity(new_velocity) - local vel_sum = vector.subtract(new_velocity,vel) - self.object:add_velocity(vel_sum) - + --new_velocity = vector.subtract(new_velocity,vel) end + self.object:add_velocity(new_velocity) + end diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 0f08c04..7e19f71 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -183,6 +183,7 @@ function airutils.logic(self) local velocity = self.object:get_velocity() local curr_pos = self.object:get_pos() self._curr_pos = curr_pos --shared + self._last_accel = self.object:get_acceleration() self._last_time_command = self._last_time_command + self.dtime @@ -503,14 +504,6 @@ function airutils.logic(self) local limit = (self._max_speed/self.dtime) if new_accel.y > limit then new_accel.y = limit end --it isn't a rocket :/ - if not self.isinliquid then --why? because whe work water movements in the phisics code - new_accel.y = new_accel.y + airutils.gravity --gravity here - end - - local vel_to_add = vector.multiply(new_accel,self.dtime) - --vel_to_add.y = 0 - self.object:add_velocity(vel_to_add) - --self.object:set_acceleration({x=0,y=new_accel.y, z=0}) else if stop == true then self._last_accell = self.object:get_acceleration() @@ -614,6 +607,7 @@ function airutils.logic(self) airutils.testImpact(self, velocity, curr_pos) --saves last velocity for collision detection (abrupt stop) + self._last_accel = new_accel self._last_vel = self.object:get_velocity() self._last_longit_speed = longit_speed self._yaw = newyaw