i have a very rudimentary ragdoll system (which works) and i want to make it so whoever is ragdolled can very slightly control their body
this is the ragdoll code i currently have
function ragdoll(perso:Model)
for i,v in pairs(perso:GetDescendants()) do
if v:IsA("Motor6D") then
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = v.C0
a1.CFrame = v.C1
a0.Parent = v.Part0
a1.Parent = v.Part1
local b = Instance.new("BallSocketConstraint")
b.Attachment0 = a0
b.Attachment1 = a1
b.Parent = v.Parent
v:Destroy()
end
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
local firt = Instance.new("NoCollisionConstraint")
firt.Part0 = v
firt.Part1 = perso.HumanoidRootPart
firt.Parent = v
end
end
local fart = Instance.new("Attachment")
local fort = Instance.new("VectorForce")
fort.Force = Vector3.new(0, -perso.HumanoidRootPart:GetMass() * (workspace.Gravity - 50), 0)
fort.Attachment0 = fart
fort.ApplyAtCenterOfMass = true
fort.RelativeTo = Enum.ActuatorRelativeTo.World
fart.Parent = perso.HumanoidRootPart
fort.Parent = perso.HumanoidRootPart
game.ReplicatedStorage.splatter:Clone().Parent = perso.Torso
end
the “splatter” script being cloned is one that isn’t really important for this specific topic
the only thing i’ve found on this was a tutorial on how to make an ENTIRE character controller, which i feel is unnecessary for my game
i’m not sure on how to even start doing this, i am not great with userinputservice
I guess you can go for a nudge system. You connect each movement key to a function that creates a body/linear velocity in the appropriate direction. Just remember to remove it when the player lets go of the key.
Here’s a code example I ripped from one of my games.
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
bodyVelocity.Velocity = Vector3.zero
bodyVelocity.Parent = humanoidRootPart
local NUDGE_SPEED = 50
local NUDGE_TIME = 0.1
local function nudge(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
local moveDir = Vector3.zero
if inputObject.KeyCode == Enum.KeyCode.W then
moveDir = camera.CFrame.LookVector
elseif inputObject.KeyCode == Enum.KeyCode.S then
moveDir = -camera.CFrame.LookVector
elseif inputObject.KeyCode == Enum.KeyCode.A then
moveDir = -camera.CFrame.RightVector
elseif inputObject.KeyCode == Enum.KeyCode.D then
moveDir = camera.CFrame.RightVector
end
if moveDir.Magnitude > 0 then
bodyVelocity.Velocity = moveDir.Unit * NUDGE_SPEED
task.delay(NUDGE_TIME, function()
bodyVelocity.Velocity = Vector3.zero
end)
end
end
end
ContextActionService:BindAction("Nudge", nudge, false,
Enum.KeyCode.W,
Enum.KeyCode.A,
Enum.KeyCode.S,
Enum.KeyCode.D
)
The code I provided was an example and is not intended for actual use. I sent it so it can spark ideas on how you can program it yourself.
Now for the reason my code might not be working. I believe it’s because I’m parenting the BodyVelocity to the humanoidRootPart which can sometimes break when in ragdoll. try parenting the BodyVelocity to something else like the torso.
i had tried another script that i wrote based off of yours, which did the same thing, even after parenting it to the torso
both versions of the script did the same thing (change the bodyvelocity’s value but not move the part)
local u=game:GetService("UserInputService")
local cam = workspace.CurrentCamera
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e5, 0, 1e5)
bv.Velocity = Vector3.zero
bv.Parent = script.Parent
local damp = 0.96
u.InputBegan:Connect(function(fart, bart)
if bart then return end
local md = Vector3.zero
if fart.KeyCode == Enum.KeyCode.W then
md = cam.CFrame.LookVector
end
if fart.KeyCode == Enum.KeyCode.S then
md = -cam.CFrame.LookVector
end
if fart.KeyCode == Enum.KeyCode.D then
md = cam.CFrame.RightVector
end
if fart.KeyCode == Enum.KeyCode.A then
md = -cam.CFrame.RightVector
end
if md.Magnitude > 0 then
bv.Velocity = md
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
bv.Velocity *= damp
end)
neither localscripts or runcontext client scripts work in either iteration
Like I said before, it’s probably a problem with the ragdoll script you’re using. I’m not saying to rewrite it, you should just do more debugging and figure out what works for you.
My code works flawlessly using the ragdoll script I hooked up.