friction adjusts

This commit is contained in:
Alexsandro Percy 2022-01-14 07:42:40 -03:00
parent 3ae7c0df8f
commit 981c5931d4
4 changed files with 26 additions and 19 deletions

View File

@ -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 player = minetest.get_player_by_name(self.driver_name)
local retval_accel = accel; local retval_accel = accel;
local stop = false
-- player control -- player control
if player then if player then
@ -64,24 +65,26 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
--break --break
if ctrl.down then 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 acc = -5 / (longit_speed / 2) -- lets set a brake efficience based on speed
end end]]--
--total stop --total stop
--wheel break --wheel break
if longit_speed >= 0.1 then if longit_speed > 0 then
acc = -1 acc = -5
if (longit_speed + acc) < 0 then
acc = longit_speed * -1
end
end end
if longit_speed <= -0.1 then if longit_speed < 0 then
acc = 1 acc = 5
if (longit_speed + acc) > 0 then
acc = longit_speed * -1
end
end end
if abs(longit_speed) < 0.2 then
if math.abs(longit_speed) <= 0.1 then stop = true
-- do not like it here, but worked better
acc = 0
--self.object:set_acceleration(zero)
self.object:set_velocity(vector.new())
end end
end end
@ -136,7 +139,7 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
end end
return retval_accel return retval_accel, stop
end end

View File

@ -2,13 +2,15 @@ local min = math.min
local abs = math.abs local abs = math.abs
function automobiles.physics(self) function automobiles.physics(self)
local friction = 0.99
local vel=self.object:get_velocity() local vel=self.object:get_velocity()
-- dumb friction -- dumb friction
--[[if self.isonground and not self.isinliquid then if self.isonground and not self.isinliquid then
self.object:set_velocity({x= vel.x> 0.2 and vel.x*mobkit.friction or 0, --minetest.chat_send_all('okay')
self.object:set_velocity({x=vel.x*friction,
y=vel.y, y=vel.y,
z=vel.z > 0.2 and vel.z*mobkit.friction or 0}) z=vel.z*friction})
end]]-- end
-- bounciness -- bounciness
if self.springiness and self.springiness > 0 then if self.springiness and self.springiness > 0 then

View File

@ -6,7 +6,7 @@ roadster.LONGIT_DRAG_FACTOR = 0.16*0.16
roadster.LATER_DRAG_FACTOR = 30.0 roadster.LATER_DRAG_FACTOR = 30.0
roadster.gravity = automobiles.gravity roadster.gravity = automobiles.gravity
roadster.max_speed = 10 roadster.max_speed = 10
roadster.max_acc_factor = 4 roadster.max_acc_factor = 6
roadster.max_fuel = 10 roadster.max_fuel = 10
roadster.front_wheel_xpos = 10.26 roadster.front_wheel_xpos = 10.26

View File

@ -348,8 +348,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
end end
end end
local curr_pos = self.object:get_pos()
if is_attached then --and self.driver_name == self.owner then 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) local impact = automobiles.get_hipotenuse_value(velocity, self.lastvelocity)
if impact > 1 then if impact > 1 then
--self.damage = self.damage + impact --sum the impact value directly to damage meter --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 -- end correction
accel.y = -automobiles.gravity accel.y = -automobiles.gravity
self.object:set_pos(curr_pos)
self.object:set_velocity(velocity)
self.object:set_acceleration(accel) self.object:set_acceleration(accel)
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end