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
Is there any way to fix this issue? If so, how would I go about it?
Thanks for the support!