Hello! I’m working in a furniture placement module to share it in #resources:community-resources and use it in my games, but I got stopped by a problem in the maths.
(sorry for the bad grammar, my main language is not English)
I’ll explain all of the placement module math to make the understanding easier
As you can see in the image, I solved that trouble but I got another; that way doesn’t work if the ‘Y-Axis’ is not 0, but I figured out a weak solution and I’ll explain it with another image
As you can see in the image, the rectangles don’t match correctly with the target, now I’ll
show a video of the module working in the game
The function that calculates the position of the object it’s this
local function calculatePosition()
local normal = Vector3.new(0, 0, 1) -- Example face
local position = raycastResult.Position -- Position
local pos = CFrame.lookAt(position, position + normal) + (model.PrimaryPart.Size * normal / 2)
return pos
end
I have had this exact problem and tried the same solution as you before, and just know that it is indeed a lot more complicated than you would have thought when you were first getting into it. I believe this thread should help you here: Creating A Furniture Placement System
local function calculatePosition()
local normal = Vector3.new(0, 0, 1) -- Example face
local position = raycastResult.Position -- Position
local pos = CFrame.lookAt(position, position + normal) + ( model.PrimaryPart.Size/2 ) * normal
return pos
end
I made a program that sets the players rotation to be perpendicular with it in all axis’s I used the fourth dimension lol. I suppose you could check the -LookVector too then i guess faux.rbxl (22.3 KB)
local scalar, faux, difference = getScalar(char)
local normal = getNormal(char, faux)
local force = scalar * normal
attractor.Force = force
local u = char.HumanoidRootPart.CFrame.UpVector
local axis = u:Cross(normal)
char.LowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * getRotationBetween(u, -normal, axis)
NOTE: you may also need to apply its cframe to be relative to the walls vector space
Yep, we both use the same technique from @EgoMooseadvanced CFrame technique to find the rotation between two vectors: a part’s current axis normal or up vector, and the normal vector of the surface we want. For @CoderHusk example be aware that the normal he obtained was reversed because of the vector math he did so he had to make it negative but yeah it should work.
It’s pretty powerful for aligning a CFrame to match the desired axis that we won’t like how this wedge UpVector is able to align to the normal surface of the sphere through raycasting in this example script I gave which you can copy and paste to try it out:
I think it should work if I want to adjust the part axis, but I watched the code and I don’t see which part of the code will adjust the position offset(And if I do from my self I think I will get the same result as the second example of the post). Also, I need to say that my math knowledge is very basic.
Oh my bad I didnt realize they were geometric. I suppose what you can do is cast a ray on all of its normals (front, left, right, back) and then find the delta magnitude difference of the current position and the rays normal. From there you can simply reset its position to be a increment of the delta change