Hello everyone, im making a fly ability right now but i cannot for the life of me figure out how to make sideways flying.
can anyone help me? im kinda dumb
-- Config
local speed = 50
-- Variables
local cam = game:GetService("Workspace").CurrentCamera
local plr = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local velocity = Instance.new("LinearVelocity")
velocity.Name = "FlyVelocity"
velocity.MaxForce = 9999
velocity.Enabled = true
local walkKeys = {Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D}
-- Logic
game:GetService("RunService").RenderStepped:Connect(function()
local char = plr.Character
if char then
local humRoot = char:FindFirstChild("HumanoidRootPart")
if humRoot then
-- Rotator
local rot2 = cam.CFrame.Rotation
local rot = cam.CFrame.LookVector
humRoot.CFrame = humRoot.CFrame:Lerp(CFrame.new(humRoot.Position, humRoot.Position + rot), .4)
velocity.VectorVelocity = Vector3.zero
-- Controller
if uis:IsKeyDown(Enum.KeyCode.W) then
velocity.VectorVelocity += Vector3.new(rot.X * speed, rot.Y * speed, rot.Z * speed)
end
if uis:IsKeyDown(Enum.KeyCode.S) then
velocity.VectorVelocity += -Vector3.new(rot.X * speed, rot.Y * speed, rot.Z * speed)
end
if uis:IsKeyDown(Enum.KeyCode.Space) then
velocity.VectorVelocity += Vector3.new(0, speed)
end
if uis:IsKeyDown(Enum.KeyCode.LeftControl) or uis:IsKeyDown(Enum.KeyCode.LeftShift) then
velocity.VectorVelocity -= Vector3.new(0, speed)
end
end
end
end)
plr.CharacterAdded:Connect(function(char)
local childAdd;
childAdd = char.ChildAdded:Connect(function(v)
if v.Name == "HumanoidRootPart" then
velocity.Parent = v
velocity.Attachment0 = v:WaitForChild("RootAttachment")
childAdd:Disconnect()
end
end)
end)
It is a localscript StarterPlayerScripts