Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- In StarterCharacterScript
- --//Variables
- local Player = game.Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Humanoid = Character:WaitForChild("Humanoid")
- local rootPart = Character.PrimaryPart
- local upperTorso = Character:WaitForChild("UpperTorso")
- local waistJoint = upperTorso:WaitForChild("Waist")
- local currentSpeed = 0
- local currentTween = nil
- --//Services
- local UIS = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- --//Code
- Humanoid.Running:Connect(function(speed)
- currentSpeed = speed
- end)
- local orginalWaistC1 = waistJoint.C1
- local maxRotation = math.rad(65)
- RunService:BindToRenderStep("vanityCamera", 400, function()
- local TargetPos = (Camera.CFrame * CFrame.new(0,0,-1000)).p
- local TorsoFront = rootPart.CFrame.LookVector
- local TorsoRight = rootPart.CFrame.RightVector
- local vectorToTarget = (TargetPos - rootPart.Position)
- local rotation = math.atan2(TorsoRight:Dot(vectorToTarget), TorsoFront:Dot(vectorToTarget))
- if (rotation < -maxRotation) then
- rotation = -maxRotation
- elseif (rotation > maxRotation) then
- rotation = maxRotation
- end
- if (math.abs(rotation) == maxRotation and currentSpeed <= 0.5) then
- local newRootPartCFrame = CFrame.new(rootPart.Position, Vector3.new(TargetPos.X, TargetPos.Y, TargetPos.Z))
- currentTween = TweenService:Create(rootPart, TweenInfo.new(0.33), {
- CFrame = newRootPartCFrame
- })
- currentTween:Play()
- else
- if (currentTween and currentSpeed > 0.5) then
- if (currentTween.PlaybackState == Enum.PlaybackState.Playing) then
- currentTween:Cancel()
- end
- end
- waistJoint.C1 = CFrame.Angles(0, rotation, 0) * orginalWaistC1
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement