I have a ragdoll script for my game where when the player dies it makes them ragdoll, clones their ragdoll into their workspace and makes the original one disappear creating a “Corpse” how do i make it so it launches the corpse in the opposite direction of the attacker, for example if you kill the player while you are behind them then it launches their corpse forward, and same thing if you were to their left it’d launch them to the right etc etc…
this is my code that only launches them backwards no matter where you kill them from:
if hrp and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
local direction = -Player.Character.HumanoidRootPart.CFrame.LookVector
local force = direction * 35 -- Tune magnitude here
local partsToThrow = { "Torso", "Head", "Right Arm", "Left Arm", "Right Leg", "Left Leg" }
for _, partName in ipairs(partsToThrow) do
local part = Corpse:FindFirstChild(partName)
if part and part:IsA("BasePart") then
part.Velocity = part.Velocity + force
end
end
end
to get the direction going from the attacker towards the victim youd have to subtract the position of the victim to the position of the attacker (or other way around i dont remember) and unit
if hrp and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
local direction = (victim.HumanoidRootPart.Position - attacker.HumanoidRootPart.Position).Unit
local force = direction * 35 -- Tune magnitude here
local partsToThrow = { "Torso", "Head", "Right Arm", "Left Arm", "Right Leg", "Left Leg" }
for _, partName in ipairs(partsToThrow) do
local part = Corpse:FindFirstChild(partName)
if part and part:IsA("BasePart") then
part.Velocity = part.Velocity + force
end
end
end
In order to make the ragdoll of the corpse “launch” i would use BodyVelocity, this is much cleaner than looping through your characters parts and setting their velocity individually, and i have made a similar system in the past, except my corpse isnt a seperate model, i just disable the characters BreakJointsOnDeath property and set its Motor6D constraints to instead be BallSocketConstraints so that the limbs can freely move, but they are still attached to the character.
Someone already posted how to achieve this ragdoll effect already:
So now that we have a better ragdoll system, we just have to apply the velocity to the ragdoll with BodyVelocity. Its pretty simple, you just have to parent it to the HumanoidRootPart, set the force, and add it to the Debris game service to make it remove in a short time because the velocity in BodyVelocities dont decay.
This was my solution:
local velocity = Instance.new("BodyVelocity")
velocity.MaxForce = Vector3.new(100000, 100000, 100000)
local angle = ((RAGDOLL_POSITION - ATTACKER_POSITION).Unit * Vector3.new(30, 0, 30))
velocity.Velocity = angle
velocity.Parent = RAGDOLL_HUMANOIDROOTPART
RAGDOLL_HUMANOIDROOTPART.Anchored = false
-- This line is to randomize the ragdolls rotation for a more realistic effect:
-- RAGDOLL_HUMANOIDROOTPART.CFrame *= CFrame.Angles(math.rad(180), math.rad(math.random(-100, 100)), math.rad(math.random(-20, 20)))
game.Debris:AddItem(velocity, 0.3)
This might not work, because the BodyVelocity is now deprecated, so i would migrate it to LinearVelocity.
LinearVelocity satisfies the majority of use cases covered by the deprecated BodyVelocity mover. Although the legacy mover allows for a MaxForce vector, the typical application of that vector force was to zero a particular component, allowing the constraint to be disabled along that dimension. LinearVelocity achieves a similar effect by operating in distinct VelocityConstraintMode modes that corresponded to one (Line), two (Plane), and three (Vector) dimensions.
Additionally, the ForceLimitMode property with the option of PerAxis accommodates any applications of the vector force with all non‑zero components, such as an increase in the force along a single axis to counteract gravity.