From 981c5931d40329ceb2a52e9548a7258d0154aa59 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Fri, 14 Jan 2022 07:42:40 -0300 Subject: [PATCH] friction adjusts --- automobiles/automobiles_control.lua | 29 ++++++++++++---------- automobiles/automobiles_custom_physics.lua | 10 +++++--- automobiles_roadster/init.lua | 2 +- automobiles_roadster/roadster_entities.lua | 4 ++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/automobiles/automobiles_control.lua b/automobiles/automobiles_control.lua index c68ebea..476c92a 100755 --- a/automobiles/automobiles_control.lua +++ b/automobiles/automobiles_control.lua @@ -27,6 +27,7 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d local player = minetest.get_player_by_name(self.driver_name) local retval_accel = accel; + local stop = false -- player control if player then @@ -64,24 +65,26 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d --break if ctrl.down then - if math.abs(longit_speed) > 0 then + --[[if math.abs(longit_speed) > 0 then acc = -5 / (longit_speed / 2) -- lets set a brake efficience based on speed - end + end]]-- --total stop --wheel break - if longit_speed >= 0.1 then - acc = -1 + if longit_speed > 0 then + acc = -5 + if (longit_speed + acc) < 0 then + acc = longit_speed * -1 + end end - if longit_speed <= -0.1 then - acc = 1 + if longit_speed < 0 then + acc = 5 + if (longit_speed + acc) > 0 then + acc = longit_speed * -1 + end end - - if math.abs(longit_speed) <= 0.1 then - -- do not like it here, but worked better - acc = 0 - --self.object:set_acceleration(zero) - self.object:set_velocity(vector.new()) + if abs(longit_speed) < 0.2 then + stop = true end end @@ -136,7 +139,7 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d end - return retval_accel + return retval_accel, stop end diff --git a/automobiles/automobiles_custom_physics.lua b/automobiles/automobiles_custom_physics.lua index 13b4074..9614aa3 100755 --- a/automobiles/automobiles_custom_physics.lua +++ b/automobiles/automobiles_custom_physics.lua @@ -2,13 +2,15 @@ local min = math.min local abs = math.abs function automobiles.physics(self) + local friction = 0.99 local vel=self.object:get_velocity() -- dumb friction - --[[if self.isonground and not self.isinliquid then - self.object:set_velocity({x= vel.x> 0.2 and vel.x*mobkit.friction or 0, + if self.isonground and not self.isinliquid then + --minetest.chat_send_all('okay') + self.object:set_velocity({x=vel.x*friction, y=vel.y, - z=vel.z > 0.2 and vel.z*mobkit.friction or 0}) - end]]-- + z=vel.z*friction}) + end -- bounciness if self.springiness and self.springiness > 0 then diff --git a/automobiles_roadster/init.lua b/automobiles_roadster/init.lua index 868d734..9169ccc 100755 --- a/automobiles_roadster/init.lua +++ b/automobiles_roadster/init.lua @@ -6,7 +6,7 @@ roadster.LONGIT_DRAG_FACTOR = 0.16*0.16 roadster.LATER_DRAG_FACTOR = 30.0 roadster.gravity = automobiles.gravity roadster.max_speed = 10 -roadster.max_acc_factor = 4 +roadster.max_acc_factor = 6 roadster.max_fuel = 10 roadster.front_wheel_xpos = 10.26 diff --git a/automobiles_roadster/roadster_entities.lua b/automobiles_roadster/roadster_entities.lua index 63d491c..46dec2c 100755 --- a/automobiles_roadster/roadster_entities.lua +++ b/automobiles_roadster/roadster_entities.lua @@ -348,8 +348,8 @@ minetest.register_entity("automobiles_roadster:roadster", { end end + local curr_pos = self.object:get_pos() if is_attached then --and self.driver_name == self.owner then - local curr_pos = self.object:get_pos() local impact = automobiles.get_hipotenuse_value(velocity, self.lastvelocity) if impact > 1 then --self.damage = self.damage + impact --sum the impact value directly to damage meter @@ -432,6 +432,8 @@ minetest.register_entity("automobiles_roadster:roadster", { -- end correction accel.y = -automobiles.gravity + self.object:set_pos(curr_pos) + self.object:set_velocity(velocity) self.object:set_acceleration(accel) if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end