[SOLVED] Smoother flight? - glider

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)
10 Likes

@Mr_Wiggles The MaxForce of your Body Velocity is just too high, you shouldn’t use math.huge because you’re forcing the velocity when the max force is extremely high, instead you should just write BodyVelocity.MaxForce = Vector3.new(100000, 100000, 100000)

1 Like

I’m so happy to finally see a reply!

I tried that just now, and the same results. Flight is still jittery. I even attempted to make it lower than you suggested.

What is your humanoid state? My guess is that the humanoid is trying to right itself in between sets of the root’s CFrame. I would try setting the state to platform stand and see if you get the same result.

4 Likes

try setting Humanoid.PlatformStand to true when flying.

2 Likes

Setting the Humanoid.PlatformStand to true solved my issue! Thank you so much! It flies so much smoother. Credit to @0000arian0000 and @KeysOfFate

1 Like

Wait, he said set it to false, not true. With all due respect, I believe I should receive the solution.

2 Likes

Both of your solutions do the same thing. The PlatformStand property is another way of changing the state directly through an easy-to-access member of the Humanoid.

Humanoid.PlatformStand = true
Humanoid:ChangeState(Enum.HumanoidStateType.PlatformStanding)

Its main intention is to check whether the Humanoid is in the PlatformStanding HumanoidStateType, but you can also use the property to read and write the state over using Change and GetState, the latter preferably being if you work with more HumanoidStateTypes.

1 Like