I’ve been having trouble with my flight system. For context, this system is based off of where the camera is facing so when moving forward it heads towards the camera direction. And this all works good, for a little while, however at some point the character’s assembly linear velocity turns into a really big number, which flings the player. Here is the code that handles movement and drag:
--portion of fly code (this jus handles drag & movement)
function FlyFlight:render(vectorForce : VectorForce , alignOrientation : AlignOrientation)
local cancelGravity = self.gravity * self.humanoidRootPart.AssemblyMass
vectorForce.Force = Vector3.new(0, cancelGravity, 0)
--apply directional movement
local moveVector = Vector3.new(self.humanoid.MoveDirection.X, self.yAxis, self.humanoid.MoveDirection.Z)
if moveVector.Magnitude > 0 then
moveVector = moveVector.Unit --normalize so that it stays between 0, and 1
local speed = moveVector * self.speed * self.humanoidRootPart.AssemblyMass
vectorForce.Force += speed
print(`y-axis:{self.yAxis} | {speed} | assemblylv: {self.humanoidRootPart.AssemblyLinearVelocity}`)
end
--apply drag
local assemblyMagnitude = self.humanoidRootPart.AssemblyLinearVelocity.Magnitude
if assemblyMagnitude > 0 then
local dragVector = -self.humanoidRootPart.AssemblyLinearVelocity
local v2 = self.humanoidRootPart.AssemblyLinearVelocity.Magnitude ^ 1.2
vectorForce.Force += dragVector * self.drag * v2 * self.humanoidRootPart.AssemblyMass
end
alignOrientation.CFrame = CFrame.lookAt(Vector3.zero, workspace.CurrentCamera.CFrame.LookVector)
end
Here is an example picture of what the output spits out:
(in the image above,“y-axis” represents force that should be applied to the y-axis [for example: if the y-value then there is no upward force, and if its -1, then there is downward force]. the 3 values right after “y-axis” is the direction and force that should be applied to the vectorForce, and "assemblylv is the linear velocity of the character’s assembly)