How would I suspend a player within scriptable movement using BodyVelocities?

Hi there, I’m JakeDRavioli - A game developer.
I am currently a little stumped on this 3D fighting game that I’m working on - The question is, How do I freely make it so the character being hit is owned by the character who is hitting, and/or how do I keep a player suspended in a singular place and then let velocities do the work for movement?
It’s stumped me for a few days as I’ve been in and out of developing the game as a side project while in college.

Any tips from other developers who have had this issue happen? Here’s the current code I’ve got that was originally working pretty well for my parkouring system.

--Script within StarterCharacterScripts
local vel = Instance.new("BodyVelocity")

vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
vel.Velocity = Vector3.new(0,0,0)
vel.Parent = script

--Event inside of script called "ChangeVelocity"
script.ChangeVelocity.Event:Connect(function(velc,isstationary)
	vel.Parent = char.PrimaryPart
	vel.Velocity = velc
	if isstationary then
		vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	else
		if velc == Vector3.zero then
			vel.Parent = script
		end
		vel.MaxForce = velc
	end
end)
--Example fire: ClassHandler_Script.ChangeVelocity:Fire(v.PrimaryPart.CFrame.LookVector * -25,true)

Ideally, the BodyVel should keep the player in place, right?
Sorry if this is a bit of a dumb question because I really haven’t been tinkering with this kind of stuff for a while.

If anyone is able to give me either a snippet of code or a suggestion on what to do, That would be incredibly helpful.
Thanks!

Just so people know, The main output I’m trying to achieve with this is that the player gets the correct knockback without glitching or stuttering. Basically, to attach the character hit to the other player or at least give them a knockback in the direction provided. This solution at this time works until the hit enemy slides like it’s on ice - Which isn’t exactly what I want, as the platform being used… Is not ice.
I’m also trying to futureproof the framework and make sure it doesn’t use welds either - Because the last time I used welds and the character died, so did the other - So it’s a pretty advanced framework I’m trying to create.

If you want to prevent them from moving then you could fire a remove from the server to the client that the client responds with this:

remotes.DisableControls.OnClientEvent:Connect(function(bool)
	local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
	
	if bool then
		controls:Disable()
	else
		controls:Enable()
	end
end)

note: it stops the game from registering their walk and jump keybinds

I have tried this, and this also isn’t what I am trying to aim for. I was intending on using this for another system to keep the main player in place when the player attacks, but it cancels all WASD movement as soon as you re-enable it.
I had to make some weird solutions for that.

But going back to what I said first, This isn’t exactly what I’m trying to aim for.
Think of a stunning knockback within a fighting game. I’m trying to achieve a knockback that doesn’t stutter or glitch, or slide like ice, without use of welds and anchoring.
I’m also trying to make this work on NPCs, so even if that solution was what I went for, it wouldn’t work for an NPC.

oh, maybe you could use ApplyImpulse as “BodyVelocity” is deprecated

Note: when using apply impulse you also have to account for their mass so using .Assembly mass when calculating the force

and if you dont want them to move during it then set the walkspeed to 0

ApplyImpulse?
I’ve never heard of that, I’ll give it a try and see if that works for what I need. I’ll keep you up to date.

Okay - So it works as intended, I just have to increase my values.
One problem is that the dummy that I am using falls over after the impulse. How do I stop that from happening?

Video: https://gyazo.com/f8a0654a85745214910db5ed830e2dbc.mp4

Edit: ApplyImpulse didn’t work. The character fails to move when the event is fired.

Sorry for the late reply but thats weird it worked for me when I did it.

This is the function I use to get my knockback force:

function module.knockBack(startPart,part : Part,multiplier,additional)
	if startPart == nil or part == nil then return end
	local knockback = startPart.CFrame.LookVector
	knockback *= part.AssemblyMass * multiplier
	if additional then
		knockback += additional
	end
	return knockback
end

note: startpart is the humanoid root part of the person punching and part is the enmy humanoid root part

From what I can tell, I’ve got a functioning knockback system now using BodyVelocity, but the problem still stands about the dummy falling over sometimes due to the push. Is there any way I can force the character to stay upright?

I am not sure of any methods but I quick google search got me this:

The link

Note: BodyGyro is now depracted and “AlignOrientation” should be used instead

Unfortunately BodyGyro can glitch out and send a dummy flying, so in this case it’s definitely been considered to use something like a completely from-scratch character controller. But…
I ended up finding a few solutions. Very, very hacky, but this is how I did it:

--Script inside of Dummy
--Character referenced as "char"
char:FindFirstChildOfClass("Humanoid").Changed:Connect(function(p)
	--print("Value changed: "..p) (ignore)
		char:FindFirstChildOfClass("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
		char:FindFirstChildOfClass("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		char:FindFirstChildOfClass("Humanoid").PlatformStand = false
		char:FindFirstChildOfClass("Humanoid").RootPart.Orientation = char:FindFirstChildOfClass("Humanoid").RootPart.Orientation * Vector3.new(0, 1, 0)
end)

A combination of all of these seems to make dummies perform exactly how I need them to.
For future notice, This question for some reason is an incredibly gray area, because not every solution works.

It’s a hacky (and probably inefficient) solution, but whatever works.
Roblox, powering your will to literally rewrite everything or find hacky solutions for (what should be) easy problems

1 Like