I got a function that moves a model that the player is placing when the mouse moves, however the model orientation is lost whenever the model is moved, how could this be fixed?
mouse.Move:Connect(function()
if placingblock then
local ignoreList = {toplace, plr.Character}
local mouseRay = mouse.UnitRay
local newRay = Ray.new(mouseRay.Origin, mouseRay.Direction.unit * 35)
target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
local RX, RY, RZ = toplace.PrimaryPart.CFrame:ToOrientation()
local endpos = Vector3.new(math.floor(pos.X),math.floor(pos.Y),math.floor(pos.Z)) + (norm * toplace.PrimaryPart.Size * .5)
toplace:SetPrimaryPartCFrame(CFrame.new(endpos))
end
end)
Thanks!
1 Like
CFrames have two arguments, positional and rotational. You’re only setting the positional, so the rotation is set back to default (negative Z axis, I believe).
Get the PrimaryPart’s rotation with local lookVector = toplace.PrimaryPart.CFrame.LookVector
, and then set the CFrame as toplace:SetPrimaryPartCFrame(CFrame.new(endpos, lookVector))
I assume that would work if I just used SetPrimaryPartCFrame with the mouse.Hit, however my method of positioning the model seems to break your method and i cannot figure out why exactly…
GIF:
![robloxapp-20200606-1257032](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/9/e/7/9e7f5e1a348ce5b9b99b465cd2eb7236460dd3fc.gif)
1 Like
After struggling with this issue for 2 weeks, i finally came up with a simple good solution
local rotX,rotY,rotZ = toplace.PrimaryPart.CFrame:ToEulerAnglesXYZ()
toplace:SetPrimaryPartCFrame(CFrame.new(endpos) * CFrame.fromEulerAnglesXYZ(rotX,rotY,rotZ))
This just shows how bad I am with CFrames X(