aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOch Noe <och_noe@forksworld.de>2020-02-02 20:25:24 +0100
committerOch Noe <och_noe@forksworld.de>2020-02-02 20:25:24 +0100
commitff355e45f6e325fe32c044ca22b258ed0eab22e0 (patch)
treed9b594b3e42cf4b3a448061a8755f15d899ee8b9
parentffedde3bd611a8f29398f9db71b198be5b23c4dc (diff)
downloadelevator-ff355e45f6e325fe32c044ca22b258ed0eab22e0.tar.gz
elevator-ff355e45f6e325fe32c044ca22b258ed0eab22e0.tar.bz2
elevator-ff355e45f6e325fe32c044ca22b258ed0eab22e0.zip
Limit the speed near the target positition
-rw-r--r--init.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 84ea482..9efd66f 100644
--- a/init.lua
+++ b/init.lua
@@ -118,8 +118,16 @@ local function create_box(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)
+ local speed = SPEED
+ if (delta_y<10) then
+ speed = 2
+ end
+
-- Set the speed.
- obj:setvelocity({x=0, y=SPEED*obj:get_luaentity().vmult, z=0})
+ -- obj:setvelocity({x=0, y=SPEED*obj:get_luaentity().vmult, z=0})
+ obj:setvelocity({x=0, y=speed*obj:get_luaentity().vmult, z=0})
obj:setacceleration({x=0, y=ACCEL*obj:get_luaentity().vmult, z=0})
-- Set the tables.
boxes[motorhash] = obj