I made a placement system its already almost done but ran into a mathematical problem
how would you get a part position to rotate off a normal I’m using normal because I have rotation mechanics in my placement system my guess is a trigonometry function (sine,cosine,tangent) but don’t know which one I should use I never really use trigonometry functions very often
any help will be appreciate heres some more depth in my question
you see when they are both 0,0,0 orientation the placement system works good!
but once you rotate one of them
theres a weird position offset
local ActivedObjectCFrame = ActivedObject.Parent:GetPrimaryPartCFrame()
local CalculatedCFrame = CFrame.new(ActivedObjectCFrame*(MouseResults.Normal*ActivedObject.Parent:GetExtentsSize()))* CFrame.Angles(math.rad(ComputedRotation.X),math.rad(ComputedRotation.Y),math.rad(ComputedRotation.Z))
clientmodel:SetPrimaryPartCFrame(CalculatedCFrame)
--The ActivedObject is the part the mouse is on
--The MouseResults is a raycast from camera to mouse
I’m not going to lie, ray casts and complicated equations are foreign to me I can only tell you what worked for me, and what didn’t. There are people out there who would do much better then me explaining what’s going on here.
Thanks for the help anyways if anyone can find the reason for this I will appreciate it I have been trying to make this placement system work for a while now barely got it to snap on other parts a couple of hours ago after 2 weeks of researching
local CalculatedCFrame = CFrame.new(ActivedObjectCFrame.Position+(MouseResults.Normal*ActivedObject.Parent:GetExtentsSize()))* CFrame.Angles(math.rad(ComputedRotation.X),math.rad(ComputedRotation.Y),math.rad(ComputedRotation.Z))
Just did so after reading your reply same problem as before
Assuming you grouped the model, you can probably derive the position of the center of the model, and depending on how far a part is from that center in 3d space, use some trigo to calculate how much you would need to offset the position to match with the rotation.
Before I get into it I want to explain what a Directional Vector is.
Here you can see that the directional vector from point A to point B is (0.7, 0.7) It’s actually (0.7071…, 0.7071…)
It’s the distance traveled in both x and y, to reach exactly 1 stud away from point A to point B.
Ok understanding that to move point A in the direction of B exactly 3 studs away we would take A (1,1) and add (Directional Vector(0.7, 0.7) * the # of studs(3))
local A = Vector2.new(1,1)
local DirectionalVector = Vector2.new(0.7071...,0.7071...)
local A1 = A + DirectionalVector * 3
The Directional Vector is what you get by MouseResults.Normal, or CFrame.UpVector.
So understanding that we can get into the problem. We’re using :GetExtentsSize() in order to find the #of studs, Just so we’re clear Multiplying Vectors together looks like this:
Lets assume the parts size is 4,2, and the directional vector we’ve already calculated is (0.26, 0.96) and our first point A is (1,1). If we multiply the directional vector by (4, 2) we get the brown point (because 0.96 * 2) is just under 2 studs. when just multiplying it by (4, 4) (or just 4) gives us the green point.
so if we take this and plug it into the equation you’re using we get:
local NewPoint = ACFrame + DirectionalVector * Vector2.new(4, 2)
Ok, so the problem here is that the Directional Vector is how far to move the point in each direction to make it 1 stud away, when moving it 4 studs away we would want to just multiply it by 4, however, we’re multiplying it by (4,2) its as if the x value was aiming for 4 studs away, and the y value was only aiming for 2 studs away.
So hopefully I’ve clearly communicated that the problem lies in multiplying the Direction by the Vector3, when it should only be multiplied by the distance away it needs to be, now the question we need to figure out is how to find which distance to use. It’s quite obvious when using UpVector, LookVector, or RightVector, because UpVector is connected to the Y value of scale. However in this case we don’t have that abililty.
So we need to figure out which face we’re trying to attach to, (Front, Top, Right, etc…) From what I’ve found the correct way it to compare our directionalVector against all of the faces directional vector. If they’re the same (or extremely close due to floating point) we’ll have found the correct face.
This post explains it well:
After we’ve found which face it’s gone through we just need to connect each face to the corresponding X, Y, or Z value of the Size.
Front and Back correlate to the X value, Top and Bottom correlate to the Y value, and Left and Right correlate to the Z value.
Hopefully this is enough information to be able to build up the fixed function on your own, if you need help feel free to DM me, and I’ll make sure you get the correct result.
Thank you for posting this problem, I had a lot of fun and learned a lot from finding the solution. I hope it helped!
Edit: Oh btw in your video it looks as if you’re drawing the ray from the character to the mouse, when it’d look more accurate if you drew it from the cameras position to the mouse.