Im trying to make a system using Ik controls. Everything has gone smoothly, except I struggle to find a solution on how to make a part (attachment) move in the same direction as the humanoid root part
I have a Move Offset (x,y,0) that works successfully as listed below.
However, using this approach on my attachment will have a different outcome, and instead the direction of the attachment varies depending on where the player is facing.
Im requesting a solution to this problem. I believe It’s probably an easy solution, but Ive been stumped on this for a bit.
Its quite a big chunk of code, but here’s some of it
local HrpPos = WallCast(Player,(HumanoidRootPart.CFrame * CFrame.new(MoveVector).Position)) -- Returns a RaycastResult
if HrpPos then
local Side = Sides[GetActionState(Player).Other.Side]
--//CurrentFoot,Hand,etc just returns a table with a IKControl, and Attachment
local CurrentHand = PlayerIKs[Player.UserId][Side.Hand]
local CurrentFoot = PlayerIKs[Player.UserId][Side.Foot]
local AlternateHand = PlayerIKs[Player.UserId][GetAlternatePart("Hand",Side.Hand)]
local AlternateFoot = PlayerIKs[Player.UserId][GetAlternatePart("Foot",Side.Foot)]
local Strafing = false
if MoveVector.X > MoveVector.Y then
Strafing = true
end
CurrentHand.Target.CFrame *= CFrame.new(MoveVector) --// What im trying to do, not working.
Part.CFrame = CurrentHand.Target.CFrame --// To visualize, same bug
TweenService:Create(HumanoidRootPart,TweenInfo.new(0.7),{Position = HrpPos.Position}):Play() -- I just tween it
The CFrame properly of Attachments is relative to the BasePart it’s parented to, while the CFrame of a BasePart is relative to the world.
You might not need to move the Attachment: if it’s parented to the HumanoidRootPart it will move with it already.
If you do need to move it, here is some code I think should work:
-- code should replace attachment.CFrame = attachment.CFrame * moveByCFrame
local attachment
local moveByCFrame
local relativeToCFrame = attachment.Parent.CFrame
local endCFrame = attachment.WorldCFrame * moveByCFrame
local relativeCFrame = relativeToCFrame:ToObjectSpace(endCFrame)
attachment.CFrame = relativeCFrame
Then I make the humanoidRootpart positioning,etc. the positioning of the humanoidRootPart appears to be accurate and doesn’t change according to the side the wall is on etc. However, the Attachments do.
(Attachments are parented to Terrain)
Edit, might be useful to say that there are 4 attachments ( 2 legs and arms) which start in positions similar to where the limb is, but higher
I think it would be easiest to just put the attachments inside their own parts. Putting them in Terrain might end up a little messy with a lot of players anyways.