Skip to content

Commit

Permalink
Turn slowdown into setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
linewriter1024 committed Jun 14, 2021
1 parent d9df0bf commit 18579de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
25 changes: 12 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 18579de

Please sign in to comment.