|
| 23 Apr 2016 11:56 AM |
So im making an elevator like the one in flood escape, where its timed and if you want to play you hop on it and it takes you down. This is what I have but it doesnt go down really well... Anyone have ideas on how to fix this or a way to make it better?
waittime = 2 speed = 20
d = 1 running = false elevator = script.Parent.Elevator elevator.BodyGyro.cframe = elevator.CFrame elevator.BodyPosition.position = elevator.Position bv = elevator.BodyVelocity levels = { } l = script.Parent.Levels:GetChildren()
if #l ~= 0 then for i = 1, #l do if l[i].className == "Part" then table.insert(levels,l[i].Position.y) end end else error("Not enough markers",0) end
table.sort(levels) script.Parent.Levels.Parent = nil -- Now that we have the height for each level, the markers are pretty much useless.
elevator.BodyPosition.position = Vector3.new(elevator.Position.x,levels[1],elevator.Position.z) while true do if math.sqrt(((levels[1]-elevator.Position.y)^2)) < 1 then break end wait() end bv.maxForce = Vector3.new(0,9.9e+005,0) wait(waittime)
elevator.Anchored = false -- ready to go, unlock platform
while true do wait() for i = 2,#levels do if running == false then bv.velocity = Vector3.new(0,speed,0) running = true end while true do wait() if elevator.Position.y >= levels[i] then bv.velocity = Vector3.new(0,0,0) elevator.BodyPosition.position = elevator.Position running=false wait(waittime) break end end end for i = #levels-1,1,-1 do if running == false then bv.velocity = Vector3.new(0,-speed,0) running = true end while true do wait() if elevator.Position.y <= levels[i] then bv.velocity = Vector3.new(0,0,0) elevator.BodyPosition.position = elevator.Position running=false wait(waittime) break end end end end
|
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 12:04 PM |
this is the perfect moment to use :lerp
it flawlessly will move a brick from one position to the next at a custom speed
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 12:07 PM |
Ill look into it! Thank you narwhal |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 12:09 PM |
here is how I would use lerp on the elevator
local startingPos = game.Workspace.Elevator.Position local endingPos = game.Workspace.Elevator.Position + Vector3.new(0,-10,0) local elevator = game.Workspace.Elevator
for ratio = 0,speed,0.1 do local newPosition = startingPos:lerp(endingPos, ratio/speed) elevator.Position = newPosition wait() end
the higher the speed, the slower it will move
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 12:16 PM |
| So then pretty much all I would have to do is define speed and change the coordinates to my liking's? |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 12:17 PM |
yes, and it will move smoothly
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
| |
|