So, I made a little flying script, but for some reason, it’s very shaky… Little help
local player = game.Players.LocalPlayer
local char = player.Character
local velocity = Instance.new("BodyVelocity", char.HumanoidRootPart)
velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local UIS = game:GetService("UserInputService")
local xDelta = 0
local zDelta = 0
local scale = 30
--[[local idle = Instance.new("Animation")
idle.AnimationId = "rbxassetid://2083818553"
local idleTrack = char.Humanoid:LoadAnimation(idle)
idleTrack:Play()
local fly = Instance.new("Animation")
fly.AnimationId = "rbxassetid://2083775002"
local flyTrack = char.Humanoid:LoadAnimation(fly)--]]
local IdleAndWalk = false
UIS.InputBegan:connect(function(input)
local i = input.KeyCode
if i == Enum.KeyCode.D then
xDelta = 5
elseif i == Enum.KeyCode.A then
xDelta = -5
elseif i == Enum.KeyCode.W then
zDelta = -5
end
end)
UIS.InputEnded:connect(function(input)
local i = input.KeyCode
if i == Enum.KeyCode.D then
if xDelta == 5 then
xDelta = 0
end
elseif i == Enum.KeyCode.A then
if xDelta == -5 then
xDelta = 0
end
elseif i == Enum.KeyCode.W then
if zDelta == -5 then
zDelta = 0
end
end
end)
game:GetService("RunService").RenderStepped:connect(function()
local cam = game.Workspace.CurrentCamera
local CameraDirection = char.HumanoidRootPart.CFrame:toObjectSpace(cam.CFrame).lookVector.unit
char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position)
* CFrame.Angles(math.asin(CameraDirection.y), 0 ,0)
print(char.HumanoidRootPart.CFrame.lookVector)
local c
if xDelta ~= 0 or zDelta ~= 0 then
--flyTrack:Play()
if zDelta ~= 0 then
if zDelta == 5 then
cf = CFrame.new(char.HumanoidRootPart.CFrame.p, char.HumanoidRootPart.CFrame*CFrame.new(0, 0, (-zDelta*scale))*CFrame.Angles(0, math.rad(xDelta*scale), 0).p)
velocity.Velocity = cf.lookVector*scale
else
cf = CFrame.new(char.HumanoidRootPart.CFrame.p, char.HumanoidRootPart.CFrame*CFrame.new(0, 0, (zDelta*scale))*CFrame.Angles(0, math.rad(xDelta*scale), 0).p)
velocity.Velocity = cf.lookVector*scale
end
else
cf = CFrame.new(char.HumanoidRootPart.CFrame.p, char.HumanoidRootPart.CFrame*CFrame.new(0, 0, -5)*CFrame.Angles(0, math.rad(xDelta*scale), 0).p)
velocity.Velocity = cf.lookVector*scale
end
else
--flyTrack:Stop()
end
if xDelta == 0 and zDelta == 0 then
velocity.Velocity = Vector3.new(0, 0, 0)
end
print(xDelta)
print(zDelta)
end)