Turn slowdown into setting.
parent
d9df0bf572
commit
18579de323
25
init.lua
25
init.lua
|
@ -5,13 +5,13 @@ local armor_path = minetest.get_modpath("3d_armor")
|
||||||
-- contains .motors loaded from mod storage
|
-- contains .motors loaded from mod storage
|
||||||
-- runtime variables and api functions
|
-- runtime variables and api functions
|
||||||
elevator = {
|
elevator = {
|
||||||
SPEED = minetest.settings:get("elevator_speed") or 10, -- Initial speed of a box.
|
SPEED = tonumber(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.
|
ACCEL = tonumber(minetest.settings:get("elevator_accel")) or 0.1, -- Acceleration of a box.
|
||||||
VISUAL_INCREASE = 1.75,
|
VISUAL_INCREASE = 1.75,
|
||||||
VERSION = 8, -- Elevator interface/database version.
|
VERSION = 8, -- Elevator interface/database version.
|
||||||
PTIMEOUT = minetest.settings:get("elevator_time") or 120, -- Maximum time a box can go without players nearby.
|
PTIMEOUT = tonumber(minetest.settings:get("elevator_time")) or 120, -- Maximum time a box can go without players nearby.
|
||||||
SLOW_DIST = 16,
|
SLOW_DIST = tonumber(minetest.settings:get("elevator_slow_dist")) or 16,
|
||||||
SLOW_SPEED = 1.75,
|
SLOW_SPEED_FACTOR = tonumber(minetest.settings:get("elevator_slow_speed_factor")) or 0.11,
|
||||||
boxes = {}, -- Elevator boxes in action.
|
boxes = {}, -- Elevator boxes in action.
|
||||||
lastboxes = {}, -- Player near box timeout.
|
lastboxes = {}, -- Player near box timeout.
|
||||||
riding = {}, -- Players riding boxes.
|
riding = {}, -- Players riding boxes.
|
||||||
|
@ -51,13 +51,12 @@ elevator.create_box = function(motorhash, pos, target, sender)
|
||||||
obj:get_luaentity().target = target
|
obj:get_luaentity().target = target
|
||||||
obj:get_luaentity().halfway = {x=pos.x, y=(pos.y+target.y)/2, z=pos.z}
|
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
|
obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1
|
||||||
|
|
||||||
-- FIX for "overshooting"
|
-- FIX for "overshooting"
|
||||||
local delta_y = math.abs(pos.y-target.y)
|
local delta_y = math.abs(pos.y - target.y)
|
||||||
|
|
||||||
local speed = elevator.SPEED
|
local speed = elevator.SPEED
|
||||||
if (delta_y<elevator.SLOW_DIST) then
|
if delta_y < elevator.SLOW_DIST then
|
||||||
speed = elevator.SLOW_SPEED
|
speed = elevator.SPEED * elevator.SLOW_SPEED_FACTOR
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the speed.
|
-- 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
|
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 p = vector.round({x=pos.x, y=y, z=pos.z})
|
||||||
local node = get_node(p)
|
local node = get_node(p)
|
||||||
if vector.distance(p,self.target) < elevator.SLOW_DIST then
|
if vector.distance(p,self.target) < elevator.SLOW_DIST then
|
||||||
self.object:set_velocity({x=0, y=elevator.SLOW_SPEED*self.vmult, z=0})
|
self.object:set_velocity({x=0, y=elevator.SPEED*elevator.SLOW_SPEED_FACTOR*self.vmult, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
if node.name == "elevator:shaft" then
|
if node.name == "elevator:shaft" then
|
||||||
-- Nothing, just continue on our way.
|
-- Nothing, just continue on our way.
|
||||||
|
|
|
@ -6,3 +6,9 @@ elevator_accel (Elevator acceleration) float 0.1
|
||||||
|
|
||||||
# Maximum time a box can go without players nearby.
|
# Maximum time a box can go without players nearby.
|
||||||
elevator_time (Maximum idle time without players) int 120
|
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
|
||||||
|
|
Loading…
Reference in New Issue