Trying to make my part's rotation the same as the character's right foot / hand

so if my part’s ray hits the right foot of a character, i want my part to match that rotation if it makes sense so it looks like the part is swinging like the right foot in the running animation. how would you do that? ty

server script:

local rcParams = RaycastParams.new()
rcParams.FilterDescendantsInstances = {
	workspace.Terrain,
}
rcParams.FilterType = Enum.RaycastFilterType.Exclude
local rs = game:GetService("RunService")

local function onHeartbeat()
	local rayCast:RaycastResult = workspace:Raycast(origin, direction, rcParams)
	if rayCast then
		print(rayCast.Instance)
		if rayCast.Instance.Name == "RightFoot" then
			rcPart.Orientation = rayCast.Instance.Orientation
		end
	end

end

rs.Heartbeat:Connect(onHeartbeat)

you’re on the right path with your script, but parts don’t have an Orientation property for individual joints like the RightFoot directly. Instead, you’ll want to use the CFrame of the foot and apply that to your part to match its rotation:

local rcParams = RaycastParams.new()
rcParams.FilterDescendantsInstances = {workspace.Terrain}
rcParams.FilterType = Enum.RaycastFilterType.Exclude
local rs = game:GetService("RunService")

local function onHeartbeat()
	local rayCast:RaycastResult = workspace:Raycast(origin, direction, rcParams)
	if rayCast then
		print(rayCast.Instance)
		if rayCast.Instance.Name == "RightFoot" then
			-- Match the CFrame
			rcPart.CFrame = CFrame.new(rcPart.Position) * rayCast.Instance.CFrame.Rotation
		end
	end
end

rs.Heartbeat:Connect(onHeartbeat)
1 Like

absolutely perfect, thanks a million vamp you’re a legend. :+1:

i had no clue man lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.