Ikcontrol pointing to the centre

How do I make an IKControl instead of pointing at the centre of a part to point at the surface of a part

Right now, the hand is trying to match the position AND the rotation of the attachment in the part.

Try setting the IKControl’s Type to Position.

1 Like

it was set to position in the video

You can either add a attachment on top of the part u want or try adjusting the offset in IKControl Properties

i think the only solution is with raycasting

you can add invisible part on top to represent surface

i dont get what you mean‎ ‎ ‎ ‎

image

green part: a normal part but invisible that represent surface
gray: your part example

make ik control point to green part

i get it now, but its not that i want it to point to the top surface, i want it to point to the closest surface

Here what I would do:

  1. Add an attachment on each face of the part
  2. Have a LocalScript to find the nearest attachment
  3. Set IKControl’s target to nearest attachment

It should set the target to the closest attachment (surface).

local maxRange = 10 -- how far away attachments can be
local attachments = workspace.Part:GetChildren() -- get the children of the part with attachments
local hand = char.LeftHand -- the body part with IKControl
local control = hand.IKControl -- or whatever it is

local function getNearestAttachment(attachmentList, maxDist)
  local nearest, nearestDist = nil, nil
  for _, attachment in pairs(attachmentList) do
    if not attachment:IsA("Attachment") then
      continue
    end

    local dist = (hand.Position - attachment.WorldCFrame.Position).Magnitude
    if not nearest and dist <= maxDist then
      nearest = attachment
      nearestDist = dist
    elseif nearest and dist <= maxDist then
      nearest = attachment
      nearestDist = dist
    else
      continue
    end

    return nearest
end

game:GetService("RunService").RenderStepped:Connect(function()
  control.Target = getNearestAttachment(attachments, maxRange)
end)
1 Like

yes, this works really well. Thank you

1 Like

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