Attachment Orientations Not Working (Rust Building System)

  1. What do you want to achieve? Keep it simple and clear!
    I would like to fix my attachments orientation. So basically I am trying to make a rust building system, and I want the bases/foundations to line up so that you can snap more on the front/back/left and right.

  2. What is the issue? Include screenshots / videos if possible!
    The attachments get messed up.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum.

Heres my code:

local wallCFrame = RaycastInstance.CFrame * CFrame.new(attachment.Position)
wallCFrame = wallCFrame * CFrame.new(-Structure.FoundationAttachment.Position)
wallCFrame = wallCFrame * CFrame.Angles(0, math.rad(attachment.Orientation.Y), 0)
Structure.CFrame = wallCFrame

This is what happens:



and only the one attachment works:

That is what I want it to do on all 4 sides of the base/foundation

When referencing attachment positions or CFrames, remember to use the
WorldCFrame.

Try changing it to this code and let me know if it works!

local wallCFrame = RaycastInstance.CFrame * attachment.WorldCFrame
wallCFrame = wallCFrame * CFrame.new(-Structure.FoundationAttachment.WorldCFrame.Position)
wallCFrame = wallCFrame * CFrame.Angles(0, math.rad(attachment.WorldCFrame.Orientation.Y), 0)
Structure.CFrame = wallCFrame

Ill try it but i don’t think that has anything to do with it, its something with positioning, cframe and orientation. Something is messed up. I think its because it chooses an attachment in the part but in the part there are multiple attachments with the same name. But i changed that and it still didn’t work. So i don’t think ill ever fix this

It could be, the normal CFrame and position of an attachment has a slight offset from the real cframe and position which is why I suggested to use WorldCFrame. I perceived from the images that there was a slight offset of the positions. Thats why I suggested it. If its not that It could simply be a small miscalculation.

Have you tried it yet? Let me know! :grin:

1 Like

it didnt work, but what did work for me was this post: How to rotate part according to attachments orientation - #11 by dthecoolest

However I have one problem. The script that was used in there that solved the problem sorta works on mine. Sometimes it works and other times it doesn’t. So here is what it looks like when it works:

And then here is what it looks like when it doesn’t work:

Here is the code I used:

local floorCframe = RaycastInstance.CFrame * CFrame.new(attachment.Position)
local emptyVector = Vector3.new(0,0,0)
local attachmentWorldUpvector = attachment.SecondaryAxis
local attachmentWorldRightvector = attachment.Axis

local goalRotationCFrame = CFrame.fromMatrix(emptyVector,attachmentWorldRightvector,attachmentWorldUpvector)
floorCframe = floorCframe * goalRotationCFrame
floorCframe = floorCframe * CFrame.new(-Structure.FloorAttachment.Position)
Structure.CFrame = floorCframe

And here is the code they used on the post:

--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.SecondaryAxis
local attachmentWorldRightvector = ClosestAttachment.Axis

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