Advertisement
ScottyMcPiper

Linear Auto-Rotate Transitions

Sep 29th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. local Char = player.Character
  2. local Root = player.Character.HumanoidRootPart
  3. local Time
  4. local TraverseTime
  5.  
  6. local GoalRad
  7. local calc
  8.  
  9.  
  10. game:GetService("RunService").RenderStepped:Connect(function()
  11.  
  12. local rot = require(player.PlayerScripts.ControlScript.MasterControl):GetMoveVector()
  13.  
  14. local RotGoal = {}
  15.  
  16. if rot == Vector3.new(0,0,-1) then
  17.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(0) + math.rad(player.CamRot.Value),0)
  18.     GoalRad = math.rad(0) + math.rad(player.CamRot.Value)
  19.    
  20. elseif rot == Vector3.new(0,0,1) then
  21.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(180) + math.rad(player.CamRot.Value),0)
  22.     GoalRad = math.rad(180) + math.rad(player.CamRot.Value)
  23.    
  24. elseif rot == Vector3.new(1,0,0) then
  25.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(-90) + math.rad(player.CamRot.Value),0)
  26.     GoalRad = math.rad(-90) + math.rad(player.CamRot.Value)
  27.    
  28. elseif rot == Vector3.new(-1,0,0) then
  29.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(90) + math.rad(player.CamRot.Value),0)
  30.     GoalRad = math.rad(90) + math.rad(player.CamRot.Value)
  31.    
  32. elseif rot == Vector3.new(1,0,-1) then
  33.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(-45) + math.rad(player.CamRot.Value),0)
  34.     GoalRad = math.rad(-45) + math.rad(player.CamRot.Value)
  35.    
  36. elseif rot == Vector3.new(-1,0,-1) then
  37.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(45) + math.rad(player.CamRot.Value),0)
  38.     GoalRad = math.rad(45) + math.rad(player.CamRot.Value)
  39.    
  40. elseif rot == Vector3.new(-1,0,1) then
  41.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(135) + math.rad(player.CamRot.Value),0)
  42.     GoalRad = math.rad(135) + math.rad(player.CamRot.Value)
  43.    
  44. elseif rot == Vector3.new(1,0,1) then
  45.     RotGoal.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0,math.rad(-135) + math.rad(player.CamRot.Value),0)
  46.     GoalRad = math.rad(-135) + math.rad(player.CamRot.Value)
  47.    
  48. elseif rot == Vector3.new(0,0,0) then
  49.     GoalRad = 0 + math.rad(player.CamRot.Value)
  50. end
  51.  
  52. local Base = .65
  53.  
  54. calc = math.abs(GoalRad - math.rad(Root.Orientation.Y))
  55.  
  56. if calc > math.rad(180) or calc < math.rad(-180) then
  57. local correct = math.abs(math.rad(360) - calc)
  58. Time = Base * correct
  59. Char.Humanoid.WalkSpeed = Char.MechSpeed.Value - (correct*Char.DeltaGradient.Value)
  60. else
  61. Time = Base * calc
  62. Char.Humanoid.WalkSpeed = Char.MechSpeed.Value - (calc*Char.DeltaGradient.Value)
  63. end
  64.  
  65.  
  66.  
  67. local RotInfo = TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
  68.  
  69.  
  70. local RotTween = TS:Create(player.Character.HumanoidRootPart,RotInfo,RotGoal)          
  71. RotTween:Play()
  72.  
  73.    
  74.     part.CFrame = cam.CFrame
  75.    
  76.     if player:FindFirstChild("CamRot") then
  77.     rs.SetRot:FireServer(part.Orientation.Y)
  78.     end
  79.    
  80.  
  81.     for i,v in pairs(game.Players:GetPlayers()) do
  82.         if v.Character and v:FindFirstChild("CamRot") then
  83.             if v.Character.Humanoid.Health > 0 then            
  84.                
  85.     local BaseTraverseTime = .7
  86.  
  87. local traversetimecalc = math.abs((math.rad(v.Character.Head.Orientation.Y) - math.rad(180)) - math.rad(v.CamRot.Value))
  88.  
  89. if traversetimecalc > math.rad(180) or traversetimecalc < math.rad(-180) then
  90. local correct = math.abs(math.rad(360) - traversetimecalc)
  91. TraverseTime = BaseTraverseTime * correct
  92. else
  93. TraverseTime = BaseTraverseTime * traversetimecalc
  94. end
  95.  
  96.     local info = TweenInfo.new(TraverseTime,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
  97.     local goal = {}
  98.     goal.C0 = CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(90) + math.rad(v.CamRot.Value) - math.rad(v.Character.HumanoidRootPart.Orientation.Y),0)
  99.     local tween = TS:Create(v.Character.Turret.Traverse,info,goal)
  100.     tween:Play()  
  101.             end
  102.         end
  103.     end
  104. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement