Advertisement
jordan83221

Vector Mimicking Rotation Matrices

Sep 28th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. local dx,dy
  2. local angle=0
  3. local next=next
  4. local pcall=pcall
  5. local atan2=math.atan2
  6. local abs=math.abs
  7. local part=game.Workspace.Part
  8. local part2=game.Workspace.Part2
  9. local x1,y1,z1,R00,R01,R02,R10,R11,R12,R20,R21,R22=part.CFrame:components()
  10. local r1,r2,r3=part.Rotation.X,part.Rotation.Y,part.Rotation.Z
  11. local n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12. local function changed(part)
  13.     local amt1,amt2,amt3,amt4,amt5,amt6,amt7,amt8,amt9,amt10,amt11,amt12,amt13,amt14,amt15=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  14.     local x2,y2,z2,R001,R011,R021,R101,R111,R121,R201,R211,R221=part.CFrame:components()
  15.     local r11,r21,r31=part.Rotation.X,part.Rotation.Y,part.Rotation.Z
  16.     if x2~=x1 or y2~=y1 or z2~=z1 or R001~=R00 or R011~=R01 or R021~=R02 or R101~=R10 or R111~=R11 or R121~=R12 or R201~=R20 or R211~= R21 or R221~= R22 or r11~=r1 or r21~=r2 or r31~=r3 then
  17.         amt1=x2-x1
  18.         amt2=y2-y1
  19.         amt3=z2-z1
  20.         amt4=R001-R00
  21.         amt5=R011-R01
  22.         amt6=R021-R02
  23.         amt7=R101-R10
  24.         amt8=R111-R11
  25.         amt9=R121-R12
  26.         amt10=R201-R20
  27.         amt11=R211-R21
  28.         amt12=R221-R22
  29.         amt13=r11-r1
  30.         amt14=r21-r2
  31.         amt15=r31-r3
  32.         x1,y1,z1,
  33.         R00,R01,R02,
  34.         R10,R11,R12,
  35.         R20,R21,R22,
  36.         n1,n2,n3,
  37.         n4,n5,n6,
  38.         n7,n8,n9,
  39.         n10,n11,n12,
  40.         n13,n14,n15=x2,y2,z2,
  41.         R001,R011,R021,
  42.         R101,R111,R121,
  43.         R201,R211,R221,
  44.         amt1,amt2,amt3,
  45.         amt4,amt5,amt6,
  46.         amt7,amt8,amt9,
  47.         amt10,amt11,amt12,
  48.         amt13,amt14,amt15
  49.         return amt1,amt2,amt3,amt4,amt5,amt6,amt7,amt8,amt9,amt10,amt11,amt12,amt13,amt14,amt15
  50.     end
  51.     --[[if x2~=x1 then
  52.         if y2~=y1 then
  53.             if z2~=z1 then
  54.                 amt1=x2-x1
  55.                 amt2=y2-y1
  56.                 amt3=z2-z1
  57.                 x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  58.                 return amt1,amt2,amt3
  59.             else
  60.                 amt1=x2-x1
  61.                 amt2=y2-y1
  62.                 x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  63.                 return amt1,amt2,amt3
  64.             end
  65.         elseif z2~=z1 then
  66.             amt1=x2-x1
  67.             amt3=z2-z1
  68.             x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  69.             return amt1,amt2,amt3
  70.         end
  71.     elseif y2~=y1 then
  72.         if z2~=z1 then
  73.             amt2=y2-y1
  74.             amt3=z2-z1
  75.             x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  76.             return amt1,amt2,amt3
  77.         else
  78.             amt2=y2-y1
  79.             x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  80.             return amt1,amt2,amt3
  81.         end
  82.     elseif z2~=z1 then
  83.         amt3=z2-z1
  84.         x1,y1,z1,n1,n2,n3=x2,y2,z2,amt1,amt2,amt3
  85.         return amt1,amt2,amt3
  86.     end]]
  87. end
  88. local function rot()
  89.     if part and part2 then
  90.         local dx=(part.CFrame.X-part2.CFrame.X)
  91.         local dy=0
  92.         local dz=(part.CFrame.Z-part2.CFrame.Z)
  93.         local angle=atan2(dz,dx)
  94.         if angle<0 and angle>-3.14 then
  95.             print("Part can still see Part 2")
  96.         else
  97.             print("Part cannot see Part 2")
  98.         end
  99.     end
  100. end
  101. local function rot2()
  102.     if changed(part) then
  103.         local x,y,z,R00,R01,R02,R10,R11,R12,R20,R21,R22=part2.CFrame:components()
  104.         local r1,r2,r3=part2.Rotation.X,part2.Rotation.Y,part2.Rotation.Z      
  105.         part2.CFrame=CFrame.new(x+n1,y+n2,z+n3,R00+n4,R01+n5,R02+n6,R10+n7,R11+n8,R12+n9,R20+n10,R21+n11,R22+n12)
  106.         --part2.Rotation=Vector3.new(r1+n13,r2+n14,r3+n15)
  107.     end
  108. end
  109. print("hi")
  110. game:service'RunService'.Stepped:connect(function() rot2() end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement