I Want To Make This First Person Supported
--- 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 originalWaistC1 = waistJoint.C1
local maxRotation = math.rad(65)
runService:BindToRenderStep("vanityCamera", 400, function()
local TargetPos = (Camera.CFrame * CFrame.new(0,0,-1000)).Position
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) * originalWaistC1
end
end)
I Tried Changing The TargetPos To Not Follow The Camera But It Didn’t Work…