Help with global size?

Hello Developers,
I addressed this topic a little while ago in another post I made., but I need help. In my game, I fire a raycast and move the object you are going to build to the position of that ray if the thing it hits meets all the criteria. But this does not account for the size of the part:
Screenshot (709)
Screenshot (710)
The second image is slightly inaccurate, due to me now changing it so the orientation of the part matches the wall it is touching. Nevertheless, it is still a problem. A user told me about the GetTouchingParts() function, which is helpful when knowing if your part is “inside” something else. Let’s say that the wall is to the right of our part and our part is stuck halfway in. I thought that using the wall’s position - it’s x size value/2 - the parts x size value/2 would work, but it does not seem to be the case. When rotating a part (like a wall), its vectors change. 90,0,0, 0,0,90, 0,90,90 all have different “X sides” (the side facing the part, since it is not the actual x side). Position is not affected by orientation, so I was wondering if I could get “Global size” somehow. I tried myself, but it ended up being so many lines of “if/then” statements that I just deemed it as inefficient and moved on to other parts of the mechanic. Any help is appreciated.

2 Likes

Convert the surface normal to object-space coordinates and multiply that by the size of the part (which is automatically in object space). Get the magnitude of that and multiply it by the surface normal, finally add all that to the position of the placed parts.

Since the parts are aligned or at least at 90 degree rotations to each other, the object-space surface normal will have two 0 components and one 1 component. Multiplying it by the size makes it have two 0 component and one component that is whatever the size of the placed part is in the direction of the surface normal.

E.g.

local moveDir = normal
local moveAmount = movedPart.CFrame:VectorToObjectSpace(normal) * movedPart.Size.Magnitude
local moveVector = moveDir * moveAmount
movedPart.CFrame += moveVector
4 Likes

Hello, Thank you for replying
I am not the best at math, but I would use raycast.Normal in the “moveDir variable” right? And also movedPart is referencing the block being moved to your cursor, right?

1 Like

Yes and yes ^.^ Hope it works!