aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOch Noe <och_noe@forksworld.de>2020-02-02 20:25:24 +0100
committerGabriel PĂ©rez-Cerezo <gabriel@gpcf.eu>2020-04-15 23:20:02 +0200
commit1cd6b661c60446f6093c3c6d92cb9a0cce0f7433 (patch)
tree3bcffe32c8306dbb65d287aec383668597d3ef87
parentbabd508a3575a268f34258032324d7ae33b0384c (diff)
downloadelevator-1cd6b661c60446f6093c3c6d92cb9a0cce0f7433.tar.gz
elevator-1cd6b661c60446f6093c3c6d92cb9a0cce0f7433.tar.bz2
elevator-1cd6b661c60446f6093c3c6d92cb9a0cce0f7433.zip
Limit the speed near the target positition
-rw-r--r--init.lua9
1 files changed, 8 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index b2eb03e..d95360f 100644
--- a/init.lua
+++ b/init.lua
@@ -50,8 +50,15 @@ 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)
+ local speed = elevator.SPEED
+ if (delta_y<10) then
+ speed = 2
+ end
+
-- Set the speed.
- obj:setvelocity({x=0, y=elevator.SPEED*obj:get_luaentity().vmult, z=0})
+ obj:setvelocity({x=0, y=speed*obj:get_luaentity().vmult, z=0})
obj:setacceleration({x=0, y=elevator.ACCEL*obj:get_luaentity().vmult, z=0})
-- Set the tables.
elevator.boxes[motorhash] = obj