| |
|
»
»
|
|
| |
Re: QUICK EDIT!
|
|
|
|
| 03 Apr 2012 04:02 PM |
I have been working on a tweenCFrame function based off of your tweenCam function. now currently this function generally works. But there are a few bugs with it. This is the function.
function tweenCFrame(Basepart,newCF,step,angleX,angleY,angleZ) -- This function could be done way more efficiently. But of course I fail at efficiency >:3 local oldCF = Basepart.CFrame x = nil y = nil z = nil if angleX == nil then x = 0 else x = angleX+1 end if angleY == nil then y = 0 else y = angleY+1 end if angleZ == nil then z = 0 else z = angleZ+1 end if Basepart == nil then return end if newCF == nil then return end if step == nil then step = 1 end for i = -90,-35,step do anglecalc = nil if i < 0 then anglecalc = 0+i*-1 elseif i > 0 then anglecalc = 90+i elseif i == 0 then anglecalc = 90 end local r = ((math.sin(math.rad(i))+1)/2) Basepart.CFrame = CFrame.new(oldCF.p:lerp(newCF.p,r)) -- For the movement Basepart.CFrame = Basepart.CFrame * CFrame.Angles(x/anglecalc*0.01,y/anglecalc*0.01,z/anglecalc*0.01) -- For the rotation print(x/anglecalc*(0.01)..","..y/anglecalc*(0.01)..","..z/anglecalc*(0.01)) print(i) wait() end end
tweenCFrame(game.Workspace.Part,CFrame.new(0,0,0),1,360,360,360)
And this is what the Output printed.
0.040111111111111,0.040111111111111,0.040111111111111 -90 0.040561797752809,0.040561797752809,0.040561797752809 -89 0.041022727272727,0.041022727272727,0.041022727272727 -88 0.041494252873563,0.041494252873563,0.041494252873563 -87 0.041976744186047,0.041976744186047,0.041976744186047 -86 0.042470588235294,0.042470588235294,0.042470588235294 -85 0.04297619047619,0.04297619047619,0.04297619047619 -84 0.043493975903614,0.043493975903614,0.043493975903614 -83 0.044024390243902,0.044024390243902,0.044024390243902 -82 0.044567901234568,0.044567901234568,0.044567901234568 -81 0.045125,0.045125,0.045125 -80 0.045696202531646,0.045696202531646,0.045696202531646 -79 0.046282051282051,0.046282051282051,0.046282051282051 -78 0.046883116883117,0.046883116883117,0.046883116883117 -77 0.0475,0.0475,0.0475 -76 0.048133333333333,0.048133333333333,0.048133333333333 -75 0.048783783783784,0.048783783783784,0.048783783783784 -74 0.049452054794521,0.049452054794521,0.049452054794521 -73 0.050138888888889,0.050138888888889,0.050138888888889 -72 0.050845070422535,0.050845070422535,0.050845070422535 -71 0.051571428571429,0.051571428571429,0.051571428571429 -70 0.05231884057971,0.05231884057971,0.05231884057971 -69 0.053088235294118,0.053088235294118,0.053088235294118 -68 0.053880597014925,0.053880597014925,0.053880597014925 -67 0.05469696969697,0.05469696969697,0.05469696969697 -66 0.055538461538462,0.055538461538462,0.055538461538462 -65 0.05640625,0.05640625,0.05640625 -64 0.057301587301587,0.057301587301587,0.057301587301587 -63 0.058225806451613,0.058225806451613,0.058225806451613 -62 0.059180327868852,0.059180327868852,0.059180327868852 -61 0.060166666666667,0.060166666666667,0.060166666666667 -60 0.061186440677966,0.061186440677966,0.061186440677966 -59 0.062241379310345,0.062241379310345,0.062241379310345 -58 0.063333333333333,0.063333333333333,0.063333333333333 -57 0.064464285714286,0.064464285714286,0.064464285714286 -56 0.065636363636364,0.065636363636364,0.065636363636364 -55 0.066851851851852,0.066851851851852,0.066851851851852 -54 0.06811320754717,0.06811320754717,0.06811320754717 -53 0.069423076923077,0.069423076923077,0.069423076923077 -52 0.07078431372549,0.07078431372549,0.07078431372549 -51 0.0722,0.0722,0.0722 -50 0.073673469387755,0.073673469387755,0.073673469387755 -49 0.075208333333333,0.075208333333333,0.075208333333333 -48 0.076808510638298,0.076808510638298,0.076808510638298 -47 0.078478260869565,0.078478260869565,0.078478260869565 -46 0.080222222222222,0.080222222222222,0.080222222222222 -45 0.082045454545455,0.082045454545455,0.082045454545455 -44 0.083953488372093,0.083953488372093,0.083953488372093 -43 0.085952380952381,0.085952380952381,0.085952380952381 -42 0.088048780487805,0.088048780487805,0.088048780487805 -41 0.09025,0.09025,0.09025 -40 0.092564102564103,0.092564102564103,0.092564102564103 -39 0.095,0.095,0.095 -38 0.097567567567568,0.097567567567568,0.097567567567568 -37 0.10027777777778,0.10027777777778,0.10027777777778 -36 0.10314285714286,0.10314285714286,0.10314285714286 -35 0.10617647058824,0.10617647058824,0.10617647058824 -34 0.10939393939394,0.10939393939394,0.10939393939394 -33 0.1128125,0.1128125,0.1128125 -32 0.11645161290323,0.11645161290323,0.11645161290323 -31 0.12033333333333,0.12033333333333,0.12033333333333 -30 0.12448275862069,0.12448275862069,0.12448275862069 -29 0.12892857142857,0.12892857142857,0.12892857142857 -28 0.1337037037037,0.1337037037037,0.1337037037037 -27 0.13884615384615,0.13884615384615,0.13884615384615 -26 0.1444,0.1444,0.1444 -25 0.15041666666667,0.15041666666667,0.15041666666667 -24 0.15695652173913,0.15695652173913,0.15695652173913 -23 0.16409090909091,0.16409090909091,0.16409090909091 -22 0.17190476190476,0.17190476190476,0.17190476190476 -21 0.1805,0.1805,0.1805 -20 0.19,0.19,0.19 -19 0.20055555555556,0.20055555555556,0.20055555555556 -18 0.21235294117647,0.21235294117647,0.21235294117647 -17 0.225625,0.225625,0.225625 -16 0.24066666666667,0.24066666666667,0.24066666666667 -15 0.25785714285714,0.25785714285714,0.25785714285714 -14 0.27769230769231,0.27769230769231,0.27769230769231 -13 0.30083333333333,0.30083333333333,0.30083333333333 -12 0.32818181818182,0.32818181818182,0.32818181818182 -11 0.361,0.361,0.361 -10 0.40111111111111,0.40111111111111,0.40111111111111 -9 0.45125,0.45125,0.45125 -8 0.51571428571429,0.51571428571429,0.51571428571429 -7 0.60166666666667,0.60166666666667,0.60166666666667 -6 0.722,0.722,0.722 -5 0.9025,0.9025,0.9025 -4 1.2033333333333,1.2033333333333,1.2033333333333 -3 1.805,1.805,1.805 -2 3.61,3.61,3.61 -1 0.040111111111111,0.040111111111111,0.040111111111111 0 0.03967032967033,0.03967032967033,0.03967032967033 1 0.039239130434783,0.039239130434783,0.039239130434783 2 0.038817204301075,0.038817204301075,0.038817204301075 3 0.038404255319149,0.038404255319149,0.038404255319149 4 0.038,0.038,0.038 5 0.037604166666667,0.037604166666667,0.037604166666667 6 0.037216494845361,0.037216494845361,0.037216494845361 7 0.036836734693878,0.036836734693878,0.036836734693878 8 0.036464646464646,0.036464646464646,0.036464646464646 9 0.0361,0.0361,0.0361 10 0.035742574257426,0.035742574257426,0.035742574257426 11 0.035392156862745,0.035392156862745,0.035392156862745 12 0.03504854368932,0.03504854368932,0.03504854368932 13 0.034711538461538,0.034711538461538,0.034711538461538 14 0.034380952380952,0.034380952380952,0.034380952380952 15 0.034056603773585,0.034056603773585,0.034056603773585 16 0.033738317757009,0.033738317757009,0.033738317757009 17 0.033425925925926,0.033425925925926,0.033425925925926 18 0.033119266055046,0.033119266055046,0.033119266055046 19 0.032818181818182,0.032818181818182,0.032818181818182 20 0.032522522522523,0.032522522522523,0.032522522522523 21 0.032232142857143,0.032232142857143,0.032232142857143 22 0.031946902654867,0.031946902654867,0.031946902654867 23 0.031666666666667,0.031666666666667,0.031666666666667 24 0.031391304347826,0.031391304347826,0.031391304347826 25 0.031120689655172,0.031120689655172,0.031120689655172 26 0.030854700854701,0.030854700854701,0.030854700854701 27 0.030593220338983,0.030593220338983,0.030593220338983 28 0.030336134453782,0.030336134453782,0.030336134453782 29 0.030083333333333,0.030083333333333,0.030083333333333 30 0.029834710743802,0.029834710743802,0.029834710743802 31 0.029590163934426,0.029590163934426,0.029590163934426 32 0.029349593495935,0.029349593495935,0.029349593495935 33 0.029112903225806,0.029112903225806,0.029112903225806 34 0.02888,0.02888,0.02888 35 0.028650793650794,0.028650793650794,0.028650793650794 36 0.028425196850394,0.028425196850394,0.028425196850394 37 0.028203125,0.028203125,0.028203125 38 0.027984496124031,0.027984496124031,0.027984496124031 39 0.027769230769231,0.027769230769231,0.027769230769231 40 0.027557251908397,0.027557251908397,0.027557251908397 41 0.027348484848485,0.027348484848485,0.027348484848485 42 0.027142857142857,0.027142857142857,0.027142857142857 43 0.026940298507463,0.026940298507463,0.026940298507463 44 0.026740740740741,0.026740740740741,0.026740740740741 45 0.026544117647059,0.026544117647059,0.026544117647059 46 0.026350364963504,0.026350364963504,0.026350364963504 47 0.026159420289855,0.026159420289855,0.026159420289855 48 0.025971223021583,0.025971223021583,0.025971223021583 49 0.025785714285714,0.025785714285714,0.025785714285714 50 0.025602836879433,0.025602836879433,0.025602836879433 51 0.025422535211268,0.025422535211268,0.025422535211268 52 0.025244755244755,0.025244755244755,0.025244755244755 53 0.025069444444444,0.025069444444444,0.025069444444444 54 0.024896551724138,0.024896551724138,0.024896551724138 55 0.02472602739726,0.02472602739726,0.02472602739726 56 0.024557823129252,0.024557823129252,0.024557823129252 57 0.024391891891892,0.024391891891892,0.024391891891892 58 0.024228187919463,0.024228187919463,0.024228187919463 59 0.024066666666667,0.024066666666667,0.024066666666667 60 0.023907284768212,0.023907284768212,0.023907284768212 61 0.02375,0.02375,0.02375 62 0.02359477124183,0.02359477124183,0.02359477124183 63 0.023441558441558,0.023441558441558,0.023441558441558 64 0.023290322580645,0.023290322580645,0.023290322580645 65 0.023141025641026,0.023141025641026,0.023141025641026 66 0.022993630573248,0.022993630573248,0.022993630573248 67 0.022848101265823,0.022848101265823,0.022848101265823 68 0.022704402515723,0.022704402515723,0.022704402515723 69 0.0225625,0.0225625,0.0225625 70 0.022422360248447,0.022422360248447,0.022422360248447 71 0.022283950617284,0.022283950617284,0.022283950617284 72 0.022147239263804,0.022147239263804,0.022147239263804 73 0.022012195121951,0.022012195121951,0.022012195121951 74 0.021878787878788,0.021878787878788,0.021878787878788 75 0.021746987951807,0.021746987951807,0.021746987951807 76 0.021616766467066,0.021616766467066,0.021616766467066 77 0.021488095238095,0.021488095238095,0.021488095238095 78 0.021360946745562,0.021360946745562,0.021360946745562 79 0.021235294117647,0.021235294117647,0.021235294117647 80 0.021111111111111,0.021111111111111,0.021111111111111 81 0.020988372093023,0.020988372093023,0.020988372093023 82 0.020867052023121,0.020867052023121,0.020867052023121 83 0.020747126436782,0.020747126436782,0.020747126436782 84 0.020628571428571,0.020628571428571,0.020628571428571 85 0.020511363636364,0.020511363636364,0.020511363636364 86 0.020395480225989,0.020395480225989,0.020395480225989 87 0.020280898876404,0.020280898876404,0.020280898876404 88 0.020167597765363,0.020167597765363,0.020167597765363 89 0.020055555555556,0.020055555555556,0.020055555555556 90
Now notice around -8 to 0 where the XYZ starters to get fairly large. Im not sure why this is happening. I think I need to rethink my math. Can anyone help? |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2012 04:04 PM |
Quick edit!
Sorry. I forgot to change a number in the function.
function tweenCFrame(Basepart,newCF,step,angleX,angleY,angleZ) -- This function could be done way more efficiently. But of course I fail at efficiency >:3 local oldCF = Basepart.CFrame x = nil y = nil z = nil if angleX == nil then x = 0 else x = angleX+1 end if angleY == nil then y = 0 else y = angleY+1 end if angleZ == nil then z = 0 else z = angleZ+1 end if Basepart == nil then return end if newCF == nil then return end if step == nil then step = 1 end for i = -90,90,step do anglecalc = nil if i < 0 then anglecalc = 0+i*-1 elseif i > 0 then anglecalc = 90+i elseif i == 0 then anglecalc = 90 end local r = ((math.sin(math.rad(i))+1)/2) Basepart.CFrame = CFrame.new(oldCF.p:lerp(newCF.p,r)) -- For the movement Basepart.CFrame = Basepart.CFrame * CFrame.Angles(x/anglecalc*0.01,y/anglecalc*0.01,z/anglecalc*0.01) -- For the rotation print(x/anglecalc*(0.01)..","..y/anglecalc*(0.01)..","..z/anglecalc*(0.01)) print(i) wait() end end |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2012 04:05 PM |
| I'm absolutely terrible at looking and interpreting math, so I'm afraid I can't really help you with the problem, sorry :\ |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2012 04:05 PM |
Mistyped a word in that post. Herp derp. This is what i ment Q_Q
Now notice around -8 to 0 where the XYZ starts to get fairly large. Im not sure why this is happening. I think I need to rethink my math. Can anyone help? |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2012 04:06 PM |
@crazyman32
Okay. Thanks anyway. I'll try to figure it out. I've been trying to make an animation system simular to how roblox animates things. Only in a more manual way. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 03 Apr 2012 04:33 PM |
Look at the wiki article on booleans and you will see that this could be a lot shorter.
function tweenCFrame(Basepart,newCF,step,angleX,angleY,angleZ) -- This function could be done way more efficiently. But of course I fail at efficiency >:3 local oldCF = Basepart.CFrame; x = angleX and angleX+1 or 0; y = angleY and angleY+1 or 0; z = angleZ and angleZ+1 or 0; if not Basepart or not newCF then return end step=step and step or 1; for i = -90,-35,(90-35)/step do local anglecalc = nil; if i < 0 then anglecalc = -i; else anglecalc = 90+i; end local r = ((math.sin(math.rad(i))+1)/2) Basepart.CFrame = CFrame.new(oldCF.p:lerp(newCF.p,r)) -- For the movement Basepart.CFrame = Basepart.CFrame * CFrame.Angles(x/anglecalc*0.01,y/anglecalc*0.01,z/anglecalc*0.01) -- For the rotation print(x/anglecalc*(0.01)..","..y/anglecalc*(0.01)..","..z/anglecalc*(0.01)) print(i) wait() end end tweenCFrame(game.Workspace.Part,CFrame.new(0,0,0),1,360,360,360)
I just simplified your script however I can't even tell what you're attempting to do. Please explain what is that this script was supposed to do? |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2012 07:17 AM |
@SDuke
Its suppost to Tween the CFrame of a brick from one place to the next. Kind of like a GUI only in XYZ |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 04 Apr 2012 04:40 PM |
Well I would do something like
--create a basic class for the rotation of the matrix local rot; local mt={ __sub=function(self,val) local new_tab={}; for i=1,#self do new_tab[i]=self[i]-val[i]; end return rot.new(CFrame.new(0,0,0,unpack(new_tab))); end, __mul=function(self,val)--Not how you multiply matricies but how we'll use it local new_tab={}; for i=1,#self do new_tab[i]=self[i]*val; end return rot.new(CFrame.new(0,0,0,unpack(new_tab))); end, __index=function(self,val) if val=="cf" then return CFrame.new(0,0,0,unpack(self)); end end }; rot={ new=function(cf) local tab={cf:components()}; table.remove(tab,1);table.remove(tab,2);table.remove(tab,3); return setmetatable(tab,mt); end };
function tween(oldCF,newCF,iterations) local iterations=iterations and iterations or 1;--max local cur_iter=1;--current local old_rot=rot.new(oldCF); local new_rot=rot.new(newCF); return function() if cur_iter<=iterations then local rotation=((new_rot-old_rot)*(cur_iter/iterations)).cf; local position=CFrame.new(oldCF.p:Lerp(newCF.p,cur_iter/iterations)); cur_iter=cur_iter+1; return position*rotation; end end end --then you just do local p=workspace.Part; local c=CFrame.new(0,0,0)*CFrame.Angles(360,360,360);--I dont understand why you would want 360 radians but... for CF in tween(p.CFrame,c,50) do p.CFrame=CF; Wait(); end
|
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 04 Apr 2012 04:48 PM |
| That doesn't work quite right..... |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 04 Apr 2012 05:37 PM |
@quenty Oh well, I made it on the spot. He should be good enough to get the errors out. |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2012 05:53 PM |
Gift from my personal collection of useless junk :>
pXYZ is position CFrame rXYZ is rotation CFrame Time is how long it takes to tween between the next CFrame object is the object you want CFramed
it goes from the objects current CFrame, and adds to it.
It's locked in a 30 FPS state.
function TweenCFrame(time,object,pX,pY,pZ,rX,rY,rZ) local fps = time * 30 for i = 1,fps do wait(time/fps) object.CFrame = object.CFrame * CFrame.Angles(0,math.rad(rY/fps),0) object.CFrame = CFrame.new(object.CFrame.X + (pX/fps), object.CFrame.Y + (pY/fps), object.CFrame.Z + (pZ/fps)) * CFrame.Angles((Vector3.new(object.CFrame:toEulerAnglesXYZ()).x)+math.rad(rX/fps), (Vector3.new(object.CFrame:toEulerAnglesXYZ()).y), (Vector3.new(object.CFrame:toEulerAnglesXYZ()).z)+math.rad(rZ/fps)) end end
|
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 04 Apr 2012 05:55 PM |
@who
You shouldn't ever use `:toEulerAnglesXYZ()` too glitchy, inaccurate and unreliable. |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2012 05:56 PM |
| Worked perfectly for me though, and I have no clue how one would get the separate angles of a brick any other way. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 04 Apr 2012 06:05 PM |
(CFrame-CFrame.p)
should give you the rotation. |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2012 06:11 PM |
| I could use that to get, say, only the Z axis ;o? |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2012 07:43 PM |
@SDuke
I was testing a full 360 degree spin of the block to make sure it would be a back to normal after rotating. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 04 Apr 2012 07:54 PM |
@clone 1. `math.rad()` converts degrees to radians so you would need `math.rad(360)` to do that 2. That would mean that the rotations are exactly the same so it would stay in exactly the same rotation the entire time. To make it do a 360 you would need multiple tweens. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 04 Apr 2012 08:14 PM |
function TweenCFrame(time,object,target)--,pX,pY,pZ,rX,rY,rZ) local pX = target.X local pY = target.Y local pZ = target.Z local rX, rY, rZ = target:toEulerAnglesXYZ() local fps = time * 30 for i = 1,fps do wait(time/fps) object.CFrame = object.CFrame * CFrame.Angles(0,math.rad(rY/fps),0) object.CFrame = CFrame.new(object.CFrame.X + (pX/fps), object.CFrame.Y + (pY/fps), object.CFrame.Z + (pZ/fps)) * CFrame.Angles((Vector3.new(object.CFrame:toEulerAnglesXYZ()).x)+math.rad(rX/fps), (Vector3.new(object.CFrame:toEulerAnglesXYZ()).y), (Vector3.new(object.CFrame:toEulerAnglesXYZ()).z)+math.rad(rZ/fps)) end end
TweenCFrame(20, Workspace.MovingPIece, Workspace.Pos2.CFrame)
That function messed up too... -____-
|
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Apr 2012 06:35 PM |
| Okay. It generally worked. But it was a bit off. |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2012 12:20 PM |
Alright. Heres a new version. Would this work?
function tweenCFrame(BasePart,newCF,step) local oldCF = BasePart.CFrame local calc = step for i = -90,90,step do local r = ((math.sin(math.rad(i))+1)/2) BasePart.CFrame = CFrame.new(oldCF.p:lerp(newCF.p,r) * CFrame.fromEulerAnglesXYZ((oldCF.CFrame.X-oldCF.CFrame.p.X)/181*calc),(oldCF.CFrame.Y-oldCF.CFrame.p.Y)/181*calc),(oldCF.CFrame.Z-oldCF.CFrame.p.Z)/181*calc)) calc = calc + step wait() end end |
|
|
| Report Abuse |
|
|
| |
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|