You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m making a flight system, however i’m having an issue with the animations. The moving animation only plays when I move to the right, the other directions still move, but don’t play the animation.
--//Services
local InputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
--//Instances
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local DefFOV = Camera.FieldOfView
local Stopped = Vector3.new(0, 0, 0)
local Force = 110000
local StartHeight = 1000
local IdleAnim = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
local ForwardAnim = Humanoid:LoadAnimation(script:WaitForChild("Forward"))
local bv = Instance.new("BodyVelocity", HRP)
bv.MaxForce = Stopped
bv.P = 10000
bv.Velocity = Stopped
bv.Name = "FlightVelocity"
local bp = Instance.new("BodyPosition", HRP)
bp.MaxForce = Stopped
bp.D = 10000
bp.P = 10000
bp.Name = "FlightPosition"
local bg = Instance.new("BodyGyro", HRP)
bg.MaxTorque = Stopped
bg.P = 10000
bg.D = 1000
bg.Name = "FlightGyro"
local Info = TweenInfo.new(2)
local Info2 = TweenInfo.new(0.7)
local DriftTime = 0.3
local FlightKey = Enum.KeyCode.F
local BoostKey = Enum.KeyCode.LeftShift
--//Data
local Flying = false
local TakeOff = false
local Boosted = false
local IsMoving = false
local BaseSpeed = 220
local BoostedSpeed = 600
local Directions = {Forward = 0, Backward = 0, Left = 0, Right = 0}
local Slowdown = TweenService:Create(bv, TweenInfo.new(DriftTime), {Velocity = Stopped})
local ZoomIn = TweenService:Create(Camera, Info2, {FieldOfView = DefFOV})
local ZoomOut = TweenService:Create(Camera, Info2, {FieldOfView = 80})
--//Functions
function Fly()
if not Flying then
if Humanoid.FloorMaterial ~= Enum.Material.Air then
TakeOff = true
IdleAnim:Play()
wait(.1)
bp.MaxForce = Vector3.new(110000, 110000, 110000)
bp.Position = HRP.Position * Vector3.new(0, StartHeight, 0)
end
Humanoid.PlatformStand = true
wait(0.25)
TakeOff = false
bp.MaxForce = Stopped
bv.MaxForce = Vector3.new(Force, Force, Force)
bg.MaxTorque = Vector3.new(Force, Force, Force)
IdleAnim:Play()
Flying = true
else
bv.MaxForce = Stopped
bg.MaxTorque = Stopped
bp.MaxForce = Stopped
IdleAnim:Stop()
ForwardAnim:Stop()
Slowdown:Cancel()
ZoomOut:Cancel()
ZoomIn:Play()
Boosted = false
IsMoving = false
Humanoid.PlatformStand = false
Flying = false
end
end
--//Events
--//Script
InputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == FlightKey then
Fly()
end
if input.KeyCode == Enum.KeyCode.W and not TakeOff then
Directions.Forward = 1
elseif input.KeyCode == Enum.KeyCode.A and not TakeOff then
Directions.Left = 1
elseif input.KeyCode == Enum.KeyCode.S and not TakeOff then
Directions.Backward = 1
elseif input.KeyCode == Enum.KeyCode.D and not TakeOff then
Directions.Right = 1
end
if input.KeyCode == BoostKey and Flying then
Boosted = true
end
end)
InputService.InputEnded:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.W then
Directions.Forward = 0
elseif input.KeyCode == Enum.KeyCode.A then
Directions.Left = 0
elseif input.KeyCode == Enum.KeyCode.S then
Directions.Backward = 0
elseif input.KeyCode == Enum.KeyCode.D then
Directions.Right = 0
end
end)
RunService.RenderStepped:Connect(function()
if Flying then
bg.CFrame = Camera.CFrame
local Speed = (Boosted and BoostedSpeed or BaseSpeed)
if IsMoving == false then
Boosted = false
end
if Directions.Forward == 1 then
bv.Velocity = Camera.CFrame.LookVector * Speed
ZoomOut:Play()
ZoomIn:Cancel()
Slowdown:Cancel()
ForwardAnim:Play()
IdleAnim:Stop()
IsMoving = true
end
if Directions.Forward == 0 then
ZoomOut:Cancel()
ZoomIn:Play()
ForwardAnim:Stop()
Slowdown:Play()
IdleAnim:Play()
end
if Directions.Backward == 1 then
bv.Velocity = -Camera.CFrame.LookVector * Speed
ZoomOut:Play()
ZoomIn:Cancel()
Slowdown:Cancel()
ForwardAnim:Play()
IdleAnim:Stop()
IsMoving = true
end
if Directions.Backward == 0 then
ZoomOut:Cancel()
ZoomIn:Play()
ForwardAnim:Stop()
Slowdown:Play()
IdleAnim:Play()
end
if Directions.Left == 1 then
bv.Velocity = -Camera.CFrame.RightVector * Speed
ZoomOut:Play()
ZoomIn:Cancel()
Slowdown:Cancel()
ForwardAnim:Play()
IdleAnim:Stop()
IsMoving = true
end
if Directions.Left == 0 then
ZoomOut:Cancel()
ZoomIn:Play()
ForwardAnim:Stop()
Slowdown:Play()
IdleAnim:Play()
end
if Directions.Right == 1 then
bv.Velocity = Camera.CFrame.RightVector * Speed
ZoomOut:Play()
ZoomIn:Cancel()
Slowdown:Cancel()
ForwardAnim:Play()
IdleAnim:Stop()
IsMoving = true
end
if Directions.Right == 0 then
ZoomOut:Cancel()
ZoomIn:Play()
ForwardAnim:Stop()
Slowdown:Play()
IdleAnim:Play()
end
if Directions.Forward == 0 and Directions.Backward == 0 and Directions.Left == 0 and Directions.Right == 0 then
wait(1)
if Directions.Forward == 0 and Directions.Backward == 0 and Directions.Left == 0 and Directions.Right == 0 and Flying then
IsMoving = false
IdleAnim:Play()
ForwardAnim:Stop()
ZoomOut:Cancel()
ZoomIn:Play()
end
end
end
end)
To add onto this, it would be extremely helpful if anybody could tell me how to make the player tilt when they turn, like seen here: https://gyazo.com/75eb3389a65b0723a227b00d9e26a205
Thank you.