I’ve been trying apply a force to the player for a while, but to no luck.
I’ve tried :ApplyImpulse()
, but it only works on a BasePart
not connected to the character, not the player character (I’m applying it to the HumanoidRootPart of the character)
I couldn’t get VectorForce
to work, either. I’m just doing some testing before I make knockback for my game.
local vec = Vector3.new(0, 10000, 0)
workspace.funnytestpart:ApplyImpulse(vec) -- Works
player.Character.HumanoidRootPart:ApplyImpulse(vec) -- Doesn't work
That’s expected. ApplyImpulse()
doesn’t work on player characters because their parts are network-owned by the client, and the physics engine won’t apply impulses from the server in that case.
Yes, you’ll need to use VectorForce
. If it didn’t work for you, its most likely a setup issue. Make sure the force is set up correctly with an Attachment
inside the HumanoidRootPart
, that the VectorForce
is parented to it, and that RelativeTo
is set correctly. The character also has to be unanchored, and the force vector should be in the right direction.
You won’t see results unless everything is configured properly. BodyVelocity
can still work for this too, even if it’s deprecated.
You do need to use VectorForce, for reasons already stated here
— basic code for when character is added
local vf = Instance.new(“VectorForce”)
local a = Instance.new(“Attachment”)
a.Parent = character.HumanoidRootPart
vf.Force = -character.HumanoidRootPart.CFrame.LookVector * f —where f is the magnitude of force
vf.Attachment0 = a
wait(n) —where n is how long the knock back lasts for
vf:Destroy()