Im making a placement system where if the cursor is close to an attachment then the part locks onto it but 3 out fo 4 of the floors don’t align properly how would I fix that?
Hmm, have you tried using an Attachments Axis and Secondary Axis and inputting that into CFrame.fromMatrix to achieve the desired rotation?
Otherwise, how have you set your attachments Axis, do the four attachments have the same axis which is why they have the same orientation for all four cases in the gif?
This is the code that deals with the rotation and it depends on the attachments orientation which isn’t provided in the question sorry.
Additionally, you want to try to use World orientation just in case.
Hmm, then when working with CFrames for debugging I suggest applying the CFrame operations one at a time so you know what exactly happens when you multiply a CFrame with another CFrame.
this is what I have done for my IK project
I would like to see a gif of what happens if you remove this piece of code relating to the rotation of the floor which seems to be incorrect and causing the problem.
After that maybe we can work out the correct CFrame rotation needed to achieve the solution.
Edit: please note with CFrame multiplication the order it happens matters as it’s not commutative.
Hmm, maybe let’s try the earlier Attachment axis approach to achieve the desired rotation, to do this we construct the axis to get the right vector and up vector of the floor:
This piece of code will change the floor CFrame according to how the attachments axis is set.
This uses CFrame from matrix which can be explained in this thread
--Put floor at attachment position via CFrame
local floorCframe = floor.CFrame *CFrame.new(ClosestAttachment.Position)
--Achieve goal rotation CFrame using axis from attachments
--We put emptyVector because we don't want to add position into the CFrame from matrix
--Only rotation using the upvector and right vector
local emptyVector = Vector3.new(0,0,0)
local attachmentWorldUpvector = ClosestAttachment.WorldSecondaryAxis
local attachmentWorldRightvector = ClosestAttachment.WorldAxis
local goalRotationCFrame = CFrame.fromMatrix(emptyVector,attachmentWorldRightvector,attachmentWorldUpvector)
--apply rotation to floor rotation
floorCframe = floorCframe * goalRotationCFrame
--Then offset the position of the floor CFrame
floorCframe = floorCframe *CFrame.new(-floor.FloorAttachment.Position)
I know this is probably old and you might not reply, but what do i replace in the script you provided to put this script in? Do i just need to add this script?