I am working on adding moving pedals to my driving game. I have an IK that gets added to the player’s Humanoid when they enter the car, and it works fine other than the knee bends backwards. I have tried using a script to add a HingeConstraint to the character on spawn, but it doesn’t affect the IK at all, it just says that it’s out of the limits.
Here’s a screenshot of the problem:
The leg in the back is the one with the problem, and the one in front is what I kind of want it to look like.
Here’s a script in StarterCharacterScripts that adds the constraint:
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
player:WaitForChild("IsInStartGUI").Value = true
game.ReplicatedStorage.Events.MainMenu:FireClient(player, true)
game.ReplicatedStorage.Events.CarAdded.Event:Connect(function(car)
if character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
local one = character.RightUpperLeg.RightKneeRigAttachment
local two = character.RightLowerLeg.RightKneeRigAttachment
local attach0 = nil
local attach1 = nil
if one:FindFirstChild("Attachment") then
attach0 = one:FindFirstChild("Attachment")
attach1 = two:FindFirstChild("Attachment")
else
attach0 = Instance.new("Attachment")
attach0.Parent = one
attach1 = Instance.new("Attachment")
attach1.Parent = two
one.WorldCFrame = two.WorldCFrame
end
local rightKneeConstraint = Instance.new("HingeConstraint")
rightKneeConstraint.Parent = character.Humanoid
rightKneeConstraint.Name = "RightKneeConstraint"
rightKneeConstraint.LimitsEnabled = true
rightKneeConstraint.UpperAngle = 10
rightKneeConstraint.LowerAngle = -90
rightKneeConstraint.Attachment0 = attach0
rightKneeConstraint.Attachment1 = attach1
end
end)
The CarAdded event runs once the player sits in the seat (which is right after they select their car).