diff options
author | Beha <shacknetisp@mail.com> | 2021-06-14 12:58:34 -0400 |
---|---|---|
committer | Beha <shacknetisp@mail.com> | 2021-06-14 12:58:34 -0400 |
commit | 18579de3234e49e5c50fc422a8309c5ea3112acb (patch) | |
tree | c2635b355dc440f850014ad8fe992659bfc7fd7b | |
parent | d9df0bf57269a24cd608b63b126d21832f6d476f (diff) | |
download | elevator-18579de3234e49e5c50fc422a8309c5ea3112acb.tar.gz elevator-18579de3234e49e5c50fc422a8309c5ea3112acb.tar.bz2 elevator-18579de3234e49e5c50fc422a8309c5ea3112acb.zip |
Turn slowdown into setting.
-rw-r--r-- | init.lua | 25 | ||||
-rw-r--r-- | settingtypes.txt | 6 |
2 files changed, 18 insertions, 13 deletions
@@ -5,13 +5,13 @@ local armor_path = minetest.get_modpath("3d_armor") -- contains .motors loaded from mod storage -- runtime variables and api functions elevator = { - SPEED = minetest.settings:get("elevator_speed") or 10, -- Initial speed of a box. - ACCEL = minetest.settings:get("elevator_accel") or 0.1, -- Acceleration of a box. + SPEED = tonumber(minetest.settings:get("elevator_speed")) or 10, -- Initial speed of a box. + ACCEL = tonumber(minetest.settings:get("elevator_accel")) or 0.1, -- Acceleration of a box. VISUAL_INCREASE = 1.75, VERSION = 8, -- Elevator interface/database version. - PTIMEOUT = minetest.settings:get("elevator_time") or 120, -- Maximum time a box can go without players nearby. - SLOW_DIST = 16, - SLOW_SPEED = 1.75, + PTIMEOUT = tonumber(minetest.settings:get("elevator_time")) or 120, -- Maximum time a box can go without players nearby. + SLOW_DIST = tonumber(minetest.settings:get("elevator_slow_dist")) or 16, + SLOW_SPEED_FACTOR = tonumber(minetest.settings:get("elevator_slow_speed_factor")) or 0.11, boxes = {}, -- Elevator boxes in action. lastboxes = {}, -- Player near box timeout. riding = {}, -- Players riding boxes. @@ -51,13 +51,12 @@ elevator.create_box = function(motorhash, pos, target, sender) obj:get_luaentity().target = target obj:get_luaentity().halfway = {x=pos.x, y=(pos.y+target.y)/2, z=pos.z} obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1 - -- FIX for "overshooting" - local delta_y = math.abs(pos.y-target.y) + -- FIX for "overshooting" + local delta_y = math.abs(pos.y - target.y) local speed = elevator.SPEED - if (delta_y<elevator.SLOW_DIST) then - speed = elevator.SLOW_SPEED - + if delta_y < elevator.SLOW_DIST then + speed = elevator.SPEED * elevator.SLOW_SPEED_FACTOR end -- Set the speed. @@ -314,9 +313,9 @@ local box_entity = { for y=self.lastpos.y,pos.y,((self.lastpos.y > pos.y) and -0.3 or 0.3) do local p = vector.round({x=pos.x, y=y, z=pos.z}) local node = get_node(p) - if vector.distance(p,self.target) < elevator.SLOW_DIST then - self.object:set_velocity({x=0, y=elevator.SLOW_SPEED*self.vmult, z=0}) - end + if vector.distance(p,self.target) < elevator.SLOW_DIST then + self.object:set_velocity({x=0, y=elevator.SPEED*elevator.SLOW_SPEED_FACTOR*self.vmult, z=0}) + end if node.name == "elevator:shaft" then -- Nothing, just continue on our way. diff --git a/settingtypes.txt b/settingtypes.txt index d950bbb..ed63604 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -6,3 +6,9 @@ elevator_accel (Elevator acceleration) float 0.1 # Maximum time a box can go without players nearby. elevator_time (Maximum idle time without players) int 120 + +# When the elevator is within this number of nodes of the destination, slow down to avoid lag. +elevator_slow_dist (Elevator slow distance) int 16 + +# Multiplier for speed when the elevator approaches its slow target. +elevator_slow_speed_factor (Elevator slow speed factor) float 0.11 |