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
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)