My current code adds a body velocity and parents it to the root part while the character is ragdolled. It gets removed 0.2 seconds later, but that’s where I run into my problem.
When the function is called the mouse position is passed into it to calculate which direction to fling the layer.
For some reason when the function is called the character accelerates towards the mouse even though the function is only called once and the body velocity was sent to debris.
local function KB(char, force, endpos)
local rootPart = char:FindFirstChild("HumanoidRootPart")
--rootPart.Velocity = Vector3.new(0, 0, 0)
local shootDirection = (rootPart.Position - endpos).Unit
local additionalVelocity = shootDirection * force
local currentVelocity = rootPart.AssemblyLinearVelocity
local newVelocity = currentVelocity + additionalVelocity
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bodyVelocity.Velocity = newVelocity
bodyVelocity.P = 1500
bodyVelocity.Parent = rootPart
bodyVelocity.Name = "RagdollKnockback"
game.Debris:AddItem(bodyVelocity, 0.2)
end
i dont entirely understand what the problem is due to your wording, but i think you can fix whatevers wrong by setting the rootpart’s velocity to zero (Vector3.zero() or Vector3.new() idk which one is more recent)
If you check the code snippet, there is a commented line that does exactly that before the character is flung. It still wont work despite setting it to 0 before, and besides, I would like every function call to modify (increase decrease) the previous velocity instead of setting it to some value.
sorry for the bad quality and horrible framerate I just grabbed the first screen recorder I could find just to demonstrate what I meant. in the video I fired the gun once but I just kept moving. the code for that is above in a module script called by a serverscript
Pretty sure @teamassists meant was set the velocity to zero after the BodyVelocity is removed.
When you take your foot off the gas pedal in a car does it instantly stop? No, because all the Parts of the car have inertia. You’ve affected all the parts of the ragdoll, so taking just the force away and setting just one Part’s LinearVelocity to 0,0,0 isn’t going to affect all of them.
From what I’ve read in other posts try using ApplyImpulse instead.
Also since BodyVelocity is deprecated you should use VectorForce in place of it in situations that call for it.