Hi. I have a fly script, but the character acts really shaky when I force it to look in the direction of the camera. How could I fix that?
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local char = player.Character
local HRP = char:WaitForChild("HumanoidRootPart")
local RS = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")
local LV = script.LinearVelocity
local speed = 50
local flying = true
local conn = nil
local clone = LV:Clone()
clone.Name = "KeeAdminLV"
function Fly(action, state)
if state == Enum.UserInputState.Begin then
if flying then
local att = Instance.new("Attachment")
att.Name = "KeeAdminAtt"
att.Parent = HRP
clone.Attachment0 = att
clone.Parent = HRP
conn = RS.RenderStepped:Connect(function()
local vel = Vector3.new(0,0,0)
if UIS:IsKeyDown(Enum.KeyCode.W) then
vel += HRP.CFrame.LookVector*speed
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
vel += HRP.CFrame.RightVector*-speed
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
vel += HRP.CFrame.LookVector*-speed
end
if UIS:IsKeyDown(Enum.KeyCode.D) then
vel += HRP.CFrame.RightVector*speed
end
if UIS:IsKeyDown(Enum.KeyCode.Space) then
vel += Vector3.new(0,1,0)*speed
end
clone.VectorVelocity = vel
local X,Y,Z = game.Workspace.CurrentCamera.CFrame.Rotation:ToEulerAngles()
HRP.CFrame = CFrame.new(HRP.Position) * CFrame.Angles(X,Y,Z)
end)
flying = false
else
if HRP:FindFirstChild("KeeAdminLV") and HRP:FindFirstChild("KeeAdminAtt") then
HRP.KeeAdminLV.VectorVelocity = Vector3.new(0,0,0)
HRP.KeeAdminAtt:Destroy()
if conn ~= nil then conn:Disconnect() end
end
flying = true
end
end
end
CAS:BindAction("Fly", Fly, true, Enum.KeyCode.E)
You can see how it offsets sometimes.