Character flinging around in my flight script

Hello. I’ve been working on a fight script recently, but I’ve run into a huge issue with BodyVelocity, where when I fly into a building or object, my character spins like crazy and doesn’t stop until I stop flying and fall to the ground.

Here’s a code snippet:

if flying then -- Stop Flying
			flying = false
			OTS_CAMERA_SYSTEM:Disable()
			--char.Humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
			char.Animate.Enabled = true
			idleAnim:Stop()
			forwardAnim:Stop()
			
		else -- Start Flying
			flying = true
			OTS_CAMERA_SYSTEM:Enable()
			--char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
			char.Animate.Enabled = false
			idleAnim:Play()
			
			local bv = Instance.new("BodyVelocity", char.PrimaryPart)
			bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bv.Velocity  = Vector3.new(0,0,0)
			bv.Name = "FlightForce"
			
			local vf = Instance.new("VectorForce", char.PrimaryPart)
			local dir = ((char.PrimaryPart.Position + char.PrimaryPart.AssemblyLinearVelocity) - char.PrimaryPart.Position).Unit
			vf.Force = -dir * drag
			
			
			repeat wait(0.1) until flying == false
			bv:Destroy()
		end
if wPressed then
			char.PrimaryPart:FindFirstChild("FlightForce").Velocity = cam.CFrame.LookVector * 600
			forwardAnim:Play()
		end
		
		if aPressed and not wPressed then
			char.PrimaryPart:FindFirstChild("FlightForce").Velocity = cam.CFrame.RightVector * -100
			forwardAnim:Play()
		end
		
		if sPressed then
			char.PrimaryPart:FindFirstChild("FlightForce").Velocity = cam.CFrame.LookVector * -100
			forwardAnim:Play()
		end
		
		if dPressed and not wPressed then
			char.PrimaryPart:FindFirstChild("FlightForce").Velocity = cam.CFrame.RightVector * 100
			forwardAnim:Play()
		end

ezgif-1-380dca98aa

Is there any way to fix this issue? If so, how would I go about it?
Thanks for the support!

Hey, I think the issue with your character spinning when flying could be due to the way you are applying the VectorForce to the character’s PrimaryPart.

When you apply a VectorForce to a part, it applies a force in the direction of the Force property. In your code, you are setting the Force property to be the opposite direction of the character’s velocity, which could cause the character to spin uncontrollably.

You can try fixing the issue by setting the Force property of the VectorForce to be the direction that the character is facing at, like this:

local vf = Instance.new("VectorForce", char.PrimaryPart)
vf.Force = (PathToCamera).CFrame.LookVector * -drag
-- Make sure to change the Path!

Hope this helps! :slight_smile:

Interesting guess. Unfortunately, It does not work. I could remove Vector Force as a whole, and it still functions the exact same. The issue isn’t with VectorForce, since VectorForce is only meant to be used as drag.

The issue is with BodyVelocity, and only when hitting a building you’re character doesn’t stay upright, as seen in the GIF provided.

Quite discouraging that nobody has any other ideas…