How to prevent body velocity flinging after root part gets unanchored

I’ve made a charging move where upon contact with an enemy it deals damage to them. The charging uses a BodyVelocity after the move hits the character is teleported in front of the enemy. However, after getting unachored the character just gets flinged wildly.

Is there any solution to fix this? Or should I use something else?
Script:

local function Attack(plr:Player,Pos)
	local Character = plr.Character
	local HRP:BasePart = Character:WaitForChild("HumanoidRootPart")
	local Head:BasePart = Character:WaitForChild("Head")
	local Humanoid = Character:WaitForChild("Humanoid")
	local PlayerStats = Character:WaitForChild("Stats")
	local MP:NumberValue = PlayerStats:WaitForChild("MP")
	local HRP:BasePart = Character:WaitForChild("HumanoidRootPart")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	local Animation = Animator:LoadAnimation(Animations.Cast)
	
	Params.FilterDescendantsInstances = {Character}
	Overlap.FilterDescendantsInstances = {Character}
	
	if MP.Value >= MPCost.Value then
		MP.Value -= MPCost.Value
	else
		CDReset.Value = true
		return
	end
	local CastSound = Sounds.Cast:Clone()
	CastSound.Parent = HRP
	
	OwnerName = plr.Name
	Damage = 90 + Humanoid:GetAttribute("ATK") * 110/100
	ExplosionDamage = 100 + Humanoid:GetAttribute("ATK") * 100/100
	
	HRP.Anchored = true
	IsCharging = true
	CastSound:Play()
	
	
	local BV = Instance.new("BodyVelocity")
	BV.Parent = HRP
	BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BV.Velocity = HRP.CFrame.LookVector * 80
	
	
	task.wait(0.3)
	coroutine.wrap(function()
		while IsCharging == true and BV do
			local Shockwave = Effects.Smash:Clone()
			Shockwave.Parent = workspace.Effects
			BV.Velocity = HRP.CFrame.LookVector * 80
			Shockwave.CFrame = HRP.CFrame * CFrame.new(Vector3.new(0,0,-3)) * CFrame.Angles(math.rad(90),0,0)
			Shockwave.Size = Vector3.new(0.1,0.1,0.1)
			Shockwave.Color = Color3.new(1, 0.666667, 0)
			TweenService:Create(Shockwave,TweenInfo.new(0.5,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out,0,false),{Transparency = 1;Size = Vector3.new(30,10,30)}):Play()
			wait()
			Debris:AddItem(Shockwave,.5)
		end
	end)()
	
	Animation:Play()
	HRP.Anchored = false
	Debris:AddItem(CastSound,2)
	Debris:AddItem(BV,3)
	
	Head.Touched:Connect(function(hit)
		if IsCharging == true and BV and hit.Parent:FindFirstChildOfClass("Humanoid") then
			local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
			local EnemyHRP:BasePart = Humanoid.Parent:WaitForChild("HumanoidRootPart")
			DamageModule.DealDamage(Damage,Humanoid.Parent)
			BV.Velocity = Vector3.new(0,0,0)
			BV.MaxForce = Vector3.new(0,0,0)
			print("HIT!")
			HRP.Anchored = true
			IsCharging = false
			BV:Destroy()
			HRP.CFrame = EnemyHRP.CFrame * CFrame.new(Vector3.new(0,0,5))
			task.wait(.4)
			HRP.Anchored = false
		end
	end)
	
	BV.Destroying:Connect(function()
		IsCharging = false
		Animation:Stop()
	end)
	
end
1 Like

Set the root part’s velocity to 0 before unanchoring, if that does not work then try setting the velocity of every part in the character model to 0

1 Like

This worked but was kind of inconsistent, but I found my own solution. Thanks for helping though!

1 Like

I am having a similar problem, what is the solution you found?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.