|
| 18 Jun 2014 01:09 AM |
I use this script to make doors slide upwards. I used what I new I could but it doesn't stop my doors from moving. Does anyone know how to make my door go up five studs, stop, and then some back down?
for i=0,5, .01 do door.CFrame = door.CFrame * CFrame.new(0,(i),0) wait(.01) end
wait(4)
for i=5,0 -.01 do door.CFrame = door.CFrame * CFrame.new(0,(i),0) wait(.01) end |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 01:33 AM |
| Im pretty sure I've had this problem before. Have you tried anchoring it? |
|
|
| Report Abuse |
|
|
| |
|
|
| 18 Jun 2014 11:22 AM |
| Use .05 and not .01. It'll work then. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:24 AM |
for i=0,5, .01 do door.CFrame = door.CFrame * CFrame.new(0,.01,0) wait(.01) end
wait(4)
for i=5,0 -.01 do door.CFrame = door.CFrame * CFrame.new(0,-.01,0) wait(.01) end
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:31 AM |
@Filiptibell
Doesn't change anything. The for loop will still never stop. You need to notice that the .01 will never equal 5 exactly. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:35 AM |
for i=1, 50 do door.CFrame = door.CFrame * CFrame.new(0,.01,0) wait() end
wait(4)
for i=1, 50 do door.CFrame = door.CFrame * CFrame.new(0,-.01,0) wait() end
|
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:40 AM |
@DrMathematica
5/.01 = 500 Unless one step in the loop isn't one step (which it always is), the loop will complete after 500 cycles. How's the math going?
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:40 AM |
| @DR that worked but it doesnt come down |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:43 AM |
It's computing. Do you not know how decimals are handled? Every wondered why, for instance, in GUIs, your numbers (.1) might turn into .100000012 or .999999998?
Because of "floating point precision." The decimals need to be able to be expressed by a power of 2. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:44 AM |
"@DR that worked but it doesnt come down"
Turn it to -.05 too... on the second one. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 18 Jun 2014 11:48 AM |
Well, too bad it works if I am supposedly wrong then...
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:50 AM |
| Unfortunately, you're lying. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:55 AM |
number = 0 for i = 0, 99 do wait() number = number + .01 print(number) end
Try it, it's full of lies.
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 11:59 AM |
You moron, look at the difference between what you posted earlier (which is what we talked about) and what you just posted.
"for i=0,5, .01 do "
"for i = 0, 99 do "
Each iteration checks to see if 'i' is equal to the end value yet. Like I said, adding .01 to 0 continuously will never equal 5. .01 cannot be expressed by a power of 2 and therefore cannot equal 5 (which can be expressed as a power of 2)
In your case you just showed, OF COURSE it will get to the end. It's adding by 1 - a normal number and not a floating point. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:02 PM |
So, I am a moron for using a loop differently? woah.
The number variable used still gets changed by .01, the example is still valid... I'd appreciate if you take all that anger and go smack a pillow or something
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:03 PM |
um i dont know why people make this so complicated.
The reason it may not work, is 1.) The Y Cframe might be different than what you expect, since CFrame takes in rotation 2.) You keep rotating by an exponential increment which can cause it to go really high
Here is a quick fix:
for i=0,5, .01 do door.CFrame = door.CFrame + Vector3.new(0,.1,0) wait(.01) end
wait(4)
for i=5,0 -.01 do door.CFrame = door.CFrame + Vector3.new(0,-.1,0) wait(.01) end |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:04 PM |
"The number variable used still gets changed by .01, the example is still valid..."
No, fool. Look at the iteration differences. The first loop is adding to the 'i' increment by .01. The second is by 1 (the default).
It doesn't matter what you do to the CFrame. Why would that affect the for loop? |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:04 PM |
| In my previous post, I meant to say "CFraming" instead of "Rotating" exponentially |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:06 PM |
number = 0 for i = 0, 1, .01 do wait() number = number + .01 print(number) end
Did it the way you wanted instead. Now go try it and check the output.
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 12:38 PM |
don't be dumb
what a for loop does:
starts as startnumber, goes up by increment, UNTIL its larger or equal to endnumber(or smaller or equal to endnumber) depends if increment is -num or +num
for I=0,5,0.01 do print(I) end
the loop does end, don't pretend you know how it works
for I=5,0,-0.01 do print(I) end
and so does this one
for I=startnumber,endnumber,increment do
end |
|
|
| Report Abuse |
|
|