Advertisement
StefanBashkir

Rotate Sphere Via Mouse

Oct 20th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. repeat wait() until Game.Players.LocalPlayer
  2. local p = game.Players.LocalPlayer
  3. local Mouse = p:GetMouse();
  4. local Ball = Workspace.Part1
  5. local cam = Workspace.CurrentCamera
  6. local A;
  7. local Button1Down = false;
  8. local AxisAngle = CFrame.fromAxisAngle;
  9. local VTOS = CFrame.new().vectorToObjectSpace;
  10.  
  11. Mouse.Button1Down:connect(function()
  12.     if (Mouse.Target) then
  13.         if (Mouse.Target == Ball) then -- Make sure it buttondown'd on the Ball
  14.             Button1Down = true;
  15.         end
  16.     end
  17. end)
  18.  
  19. Mouse.Move:connect(function()
  20.     if (Mouse.Target == Ball) and (Button1Down) then
  21.         if not (A) then
  22.             A = (Ball.Position - Mouse.Hit.p).unit;
  23.         else
  24.             local B = (Ball.Position - Mouse.Hit.p).unit
  25.             local Axis = VTOS(Ball.CFrame-Ball.CFrame.p,A:Cross(B))--[[:vectorToObjectSpace(
  26.                 A:Cross(B)
  27.             )]]
  28.             Ball.CFrame = Ball.CFrame * AxisAngle(Axis, (Axis.magnitude))
  29.             A = B;
  30.         end
  31.     end
  32. end)
  33.  
  34. Mouse.Button1Up:connect(function()
  35.     if (Button1Down) then
  36.         Button1Down = false;
  37.         A = nil;
  38.     end
  39. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement