Advertisement
oopsrainbow4

Realistic Dynamic Movement R15

Jun 15th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- In StarterCharacterScript
  2.  
  3. --//Variables
  4. local Player = game.Players.LocalPlayer
  5. local Camera = workspace.CurrentCamera
  6. local Character = Player.Character or Player.CharacterAdded:Wait()
  7. local Humanoid = Character:WaitForChild("Humanoid")
  8. local rootPart = Character.PrimaryPart
  9. local upperTorso = Character:WaitForChild("UpperTorso")
  10. local waistJoint = upperTorso:WaitForChild("Waist")
  11.  
  12. local currentSpeed = 0
  13. local currentTween = nil
  14.  
  15. --//Services
  16. local UIS = game:GetService("UserInputService")
  17. local RunService = game:GetService("RunService")
  18. local TweenService = game:GetService("TweenService")
  19.  
  20. --//Code
  21. Humanoid.Running:Connect(function(speed)
  22.     currentSpeed = speed
  23. end)
  24.  
  25. local orginalWaistC1 = waistJoint.C1
  26. local maxRotation = math.rad(65)
  27. RunService:BindToRenderStep("vanityCamera", 400, function()
  28.     local TargetPos = (Camera.CFrame * CFrame.new(0,0,-1000)).p
  29.     local TorsoFront = rootPart.CFrame.LookVector
  30.     local TorsoRight = rootPart.CFrame.RightVector
  31.     local vectorToTarget = (TargetPos - rootPart.Position)
  32.     local rotation = math.atan2(TorsoRight:Dot(vectorToTarget), TorsoFront:Dot(vectorToTarget))
  33.    
  34.     if (rotation < -maxRotation) then
  35.         rotation = -maxRotation
  36.     elseif (rotation > maxRotation) then
  37.         rotation = maxRotation
  38.     end
  39.    
  40.     if (math.abs(rotation) == maxRotation and currentSpeed <= 0.5) then
  41.         local newRootPartCFrame = CFrame.new(rootPart.Position, Vector3.new(TargetPos.X, TargetPos.Y, TargetPos.Z))
  42.         currentTween = TweenService:Create(rootPart, TweenInfo.new(0.33), {
  43.             CFrame = newRootPartCFrame
  44.         })
  45.         currentTween:Play()
  46.     else
  47.         if (currentTween and currentSpeed > 0.5) then
  48.             if (currentTween.PlaybackState == Enum.PlaybackState.Playing) then
  49.                 currentTween:Cancel()
  50.             end
  51.         end
  52.         waistJoint.C1 = CFrame.Angles(0, rotation, 0) * orginalWaistC1
  53.     end
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement