Character being sent to the void after a stun?

In my game, stun for killers is handled via a strong body velocity on the character (MaxForce = 400000,0,400000). A specific character has a move that lets him grab a survivor, holding him in place via network ownership and a bodymover (no weld). They automatically drop the survivor when they get stunned during this move.

For some reason, there is a very rare chance that the killer gets sent to the void immediately upon getting stunned out of their grab. I assume this is some sort of roblox physics engine bug with the very high values set to the bodyvelocities maxforce, but are there any work-arounds to ensure this doesn’t happen? It’s rare but its game ruining for players when it does happen.

1 Like

Hey, I am not sure how I can exactly help you, but most of the time when this happens, its because of a (NaN, NaN, NaN) vector. This may happen when you try to normalize (Vector.Unit) a vector with a magnitude of 0. This is sometimes random like in your scenario and causes similar behavior. You can send some code examples for better help.

keep the bug it sounds funny ngl

Yeah, below is the stun function inside the damage module that all stunning moves call.

Stun = function(victim,stuntime,kb,kbdir,attacker: Player)
	local hum = victim.Humanoid
	local bv
	local pos = victim.HumanoidRootPart.Position
	victim:PivotTo(CFrame.lookAt(pos,Vector3.new(kbdir.X,pos.Y,kbdir.Z)))

	local statsfolder = victim.Humanoid.Parent:FindFirstChild("Stats")

	if game.Players:GetPlayerFromCharacter(victim).Team == game.Teams.Terminator then
		game.ReplicatedStorage.Remotes.LocalVisual:FireAllClients("StunParticle",{Victim = victim})
	end

	local bv = victim.HumanoidRootPart:FindFirstChildOfClass("BodyVelocity")
	if bv ~= nil then
		bv:Destroy()
	end



	if statsfolder.StunTime.Value <= 0 then
		bv = Instance.new("BodyVelocity",victim.HumanoidRootPart)
		bv.MaxForce = Vector3.new(400000,0,400000)
		bv.Name = "StunVelocity"

		bv.Velocity = hum.Parent.HumanoidRootPart.CFrame.LookVector*-kb
		game:GetService("Debris"):AddItem(bv,4)

		local tween = tweenservice:Create(bv,TweenInfo.new(1),{Velocity = Vector3.new(0,0,0)})
		tween:Play()
		statsfolder.StunTime.Value = stuntime
	else
		statsfolder.StunTime.Value += stuntime/3
		bv = victim.HumanoidRootPart:FindFirstChild("StunVelocity")
		if bv ~= nil then
			bv.Velocity = hum.Parent.HumanoidRootPart.CFrame.LookVector*-kb
			if bv.Velocity.Magnitude > 1 then
				local tween = tweenservice:Create(bv,TweenInfo.new(1),{Velocity = Vector3.new(0,0,0)})
				tween:Play()
			end
		else
			bv = Instance.new("BodyVelocity",victim.HumanoidRootPart)
			bv.MaxForce = Vector3.new(400000,0,400000)
			bv.Name = "StunVelocity"
			bv.Velocity = Vector3.new(0,0,0)
		end
	end

end

My current lead is that it could potentially be being caused by stun-stacking? Under normal circumstances a killer shouldn’t be able to be stunned twice till their stun immunity is finished, but there is the potential that this is happening because a user escapes the grab at the same time as the killer being stunned, potentially applying the stun body velocity twice. That’s my only lead though.

If so, you can check if theres a velocity already inside the root part or just print every time a velocity is created and check if it gets printed twice.
Another issue might be the deprecation status of body velocity. The new alternative is linear velocity i think, it works great for me when creating forces.
Im not sure of the magnitude of kbdir, but if its too small then CFrame.lookAt may be inaccurate for rotation. Maybe type something like this in line 4 of your Stun function:

victim:PivotTo(CFrame.lookAt(pos, Vector3.new(kbdir.X * 1000, pos.Y, kbdir.Z * 1000)) )

You can also just limit the max force of the body velocity, instead of the character flying into the void, youll have a slightly stronger push

1 Like