Hi guys, I created a simple glider that uses BodyVelocity to propel you where your mouse is aimed at and then rotates your HumanoidRootPart to the mouse. The issue is I also have an animation that plays, and as a result, your body becomes “jittery” as you move up or down.
Example video:
https://gyazo.com/4ac5419256da1a4b1416c06e5e89580b.gif
Is there a way to create a smoother flight without making too many major changes to my current code?
Current code:
local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Torso = Character:WaitForChild('Torso')
local Root = Character:WaitForChild('HumanoidRootPart')
local Mouse = Player:GetMouse()
local Tool = script.Parent
local FlyAnimation = Tool:WaitForChild('Fly')
local HoldAnimation = Tool:WaitForChild('Hold')
Fly = Humanoid:LoadAnimation(FlyAnimation)
Hold = Humanoid:LoadAnimation(HoldAnimation)
local Holding, Flying = false, false
local BodyVelocity = Instance.new('BodyVelocity')
BodyVelocity.Name = 'GliderVelocity'
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
Tool.Equipped:Connect(function()
Hold:Play()
Holding = true
end)
Tool.Activated:Connect(function()
if not Flying then
Fly:Play()
local NewVelocity = BodyVelocity:Clone()
NewVelocity.Parent = Torso
Flying = true
while Flying do
NewVelocity.Velocity = Mouse.Hit.lookVector*60
Root.CFrame = CFrame.new(Root.Position, Root.Position + Mouse.Hit.LookVector)
wait()
end
NewVelocity:Destroy()
Fly:Stop()
elseif Flying then
Flying = false
Hold:Play()
Holding = true
end
end)
Tool.Unequipped:Connect(function()
Holding, Flying = false, false
Hold:Stop()
Fly:Stop()
end)