Gliding System Help

I have posted about this before, but I have never gotten a working answer, so here I am again.

I am trying to make a system where the player’s character is able to glide through the air with realistic physics such as Minecraft’s Elytra or Bird Simulators Bird gliding feature. Both of these have the exact result that I want to achieve, but I am not sure how it was done. I have tried to do it many times, but with no positive result. I have looked up the drag and lift equations and coefficients, but I have not been able to successfully implement them.

Does anyone know the best way to do this, or have an idea on how to do this? Thanks!

:coefficients: – get it, the emoji’s name is coefficients.

2 Likes

I would personally just use basic vector math after anchoring the rootpart of a player.

Start with making a script that moves moves the anchored rootpart foward by a fixed vector each frame

Next make it so the vector changes direction depending on the players camera angle or something
This will enable you to fly around freely

Finally once you have perfect the above add a downvector to act as gravity. Add this vector to the first vector every frame.

Flying foward will make the final vector go diagonally down towards the ground
Flying downwards will cause the gravity vector to increase the size of the first vector increasing speed
Flying up the gravity vector will be working directly against the first vector so speed will drop off a lot faster

eventually your first vector will reach a min velocity and that’s when you would land

Never attempted such a problem tho so my idea is up for testing/debate

1 Like

You could use VectorForce, its a built in instance and it can do that exact same thing.

I know about Vector Forces and how to use them and I have been trying to make my system with them, but my problem is getting the correct values and implementing them.

The most important part to having realistic flight physics is calculating the angle of attack on the wing
and the direction of the force that we need to have

and to do this we can use the dot product

local lift = 0.05
local drag = 0.001
local angularLift = 0.01
local angularDrag = 0.01

runService.Heartbeat:Connect(function(deltaTime)
	-- get the part speed
	local speed = part.AssemblyLinearVelocity.Magnitude

	-- some of flight math uses speed to the power of 2
	local speed2 = speed ^ 2
	local velocity2 = part.AssemblyLinearVelocity * part.AssemblyLinearVelocity
	local angularVelocity2 = part.AssemblyAngularVelocity * part.AssemblyAngularVelocity
	
	-- angle of attack will be a value between -1 and 1 depending on the angle between the velocity and parts orientation
	local attack = part.AssemblyLinearVelocity.Unit:Dot(part.CFrame.UpVector)

	-- drag that does not include the drag of the wings
	local dragVector = velocity2 * drag

	-- calculate the vector3 force of the wing this included both drag and lift of the wing
	local forceVector = part.CFrame:VectorToWorldSpace(Vector3.new(0, -attack * speed2 * lift, 0))

	-- make sure that the ActuatorRelativeTo is set to World
	vectorForce.Force = forceVector - dragVector



	-- now lets do rotation
	

	-- angle drag that does not include wings
	local angularDragVector = angularVelocity2 * angularDrag

	-- this will make the part want to rotate towards the velocity the same way a dart/arrow will go head first towards its direction of movement
	local angularForceVector = part.CFrame:VectorToWorldSpace(Vector3.new(attack * speed2 * angularLift, 0, 0))

	-- make sure that the ActuatorRelativeTo is set to World
	torque.Torque = angularForceVector - angularDragVector 
end)

this only does the horizontal wings not the vertical tail wing
to get the dot product of the vertical tail wing you do

local horizontalAttack = part.AssemblyLinearVelocity.Unit:Dot(part.CFrame.RightVector)
5 Likes

This looks nice, but I cannot seem to get it to work correctly. I may be implementing it wrong. Here is what I have:

-- setup of the VectorForce
local att = Instance.new("Attachment")
att.Parent = rootPart
att.Name = "Attatchment0" 
att.Position = Vector3.new(0,0,0) -- att.Orientation = Vector3.new(0, 90, -90)
local Force = rootPart:FindFirstChild("VectorForce") or Instance.new("VectorForce") 
Force.Parent = att
Force.Attachment0 = att 
Force.Enabled = false 
Force.Force = Vector3.new() 
Force.RelativeTo = Enum.ActuatorRelativeTo.World

local lift = 0.05
local drag = 0.001
local angularLift = 0.01
local angularDrag = 0.01
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
	if fly then -- fly is changed based on user input
		SetGyro(true) -- a body gyro that turns the player based on the camera's orientation
		Force.Enabled = true
		-- get the part speed
		local speed = rootPart.AssemblyLinearVelocity.Magnitude

		-- some of flight math uses speed to the power of 2
		local speed2 = speed ^ 2
		local velocity2 = rootPart.AssemblyLinearVelocity * rootPart.AssemblyLinearVelocity
		local angularVelocity2 = rootPart.AssemblyAngularVelocity * rootPart.AssemblyAngularVelocity

		-- angle of attack will be a value between -1 and 1 depending on the angle between the velocity and parts orientation
		local attack = rootPart.AssemblyLinearVelocity.Unit:Dot(rootPart.CFrame.UpVector)
		-- drag that does not include the drag of the wings
		local dragVector = velocity2 * drag

		-- calculate the vector3 force of the wing this included both drag and lift of the wing
		local forceVector = rootPart.CFrame:VectorToWorldSpace(Vector3.new(0, -attack * speed2 * lift, 0))

		-- make sure that the ActuatorRelativeTo is set to World
		Force.Force = forceVector - dragVector

        -- I do not really need rotation becuse of my BodyGyro that I use to keep rotation constant.
	else
		Force.Enabled = false
		SetGyro(false)
	end
end)

I don’t know what is wrong with it, but when I test it, the character goes backward slowly. I tested another way a while back and it had the same result. When I set the attack variable so that it used the camera’s UpVector it went the correct way but got way too much force. Is there a different way that I was supposed to implament it?

I’m not sure how your rotating your player but you might need to use
rootPart.AssemblyLinearVelocity.Unit:Dot(-rootPart.CFrame.LookVector)

If your tilting the player head first to get the correct attack value

The angle of the player is very important the player needs to first be tilted forward to pick up speed then the player needs to slowly tilt backwards to use the speed to generate lift

You also need to play with the lift and drag values they are very sensitive reduce the lift value if its adding to much force and reduce drag if it’s slowing down to quickly

Sorry About the late reply.
I have tried to change the values of the drag, and also tried making the lookvector negative, but the values that I get still cause the player to either not move enough for it to be noticed, or the player just shoots forward. The problem of direction is solved though.

My gyro is rotating the player’s character so that their head is farthest from the cam, and their feet are closest, as if they are gliding, which is what I am wanting to achieve.

Anyone have any ideas on what I can do?

Just a little bump to this because I would really like to be able to make this system work. I am trying to make a pretty cool game.

Does anyone have any ideas on how to create something like this?

This piece of code does a simple lift of wings. I used it in my game.

DotProduct = -PrimaryPart.CFrame.UpVector:Dot(AssemblyLinearVelocity.Unit)
VectorForce.Force = Vector3new(0,DotProduct * AssemblyLinearVelocity.Magnitude * DRAG_COEFFICIENT * CharacterMass,0)

You will need to modify the mass of the part and the drag coefficient so that the drag force is never more than the velocity * mass the object has. Basically in cases where the drag is more than the velocity it moves backwards and then escalates.

You can use the above formula but this is way more basic and simple. This also means that if you are flying straight ahead you will always go downward. you have to be tilted upward to fly straight.

If you want to play the broken game… EQ = ROLL
https://www.roblox.com/games/6792905423/War-of-Worlds-Battle-of-Croyium

2 Likes