Hello, i’ve been having troubles with my placement system lately, here is a video showcasing the issue.
As seen in the video, the model goes into other parts when I drag it or rotate it, and that is a problem for me.
Here is the main local script function that I use to set the models CFrame.
local function newCFrame()
if newElectronic.PrimaryPart ~= nil then
newElectronic.PrimaryPart.CFrame = CFrame.new(Mouse.Hit.Position + newElectronic:GetExtentsSize() / 2) * newAngle
end
end
I have looked at multiple dev forum posts trying to find a solution but haven’t found anything conclusive.
So that it doesn’t go into the ground or walls when I move the mouse.
Edit: I guess I wasn’t clear in explaining the issue, I will edit this post shortly
Edit 2: did I explain the issue well enough or no, I guess it was kinda unclear at first.
I guess what you could do is checking if the model is intersecting with something using workspace:GetPartsInPart(), and not let them place the model if its being intersected. It’s clipping into walls because it’s using the center of the model to decide where to place.
A alternative is getting the model’s boundingbox and going from there too.
How would I actually move the model by the boundingbox though? Or move the model away from the part that it is intersecting using workspace:GetPartsInPart()? I’ve researched a bit about this topic but I cannot find anything, I did find :PivotTo and that apparently sets the cframe of a model from the centre if no primarypart which I think is similar to what boundingbox does? I kinda have to rewrite a lot of code for this though which I don’t know if its worth doing or if it will even fix the problem of my models clipping into the walls, also I heard that :PivotTo is more efficient.
Here is my new code I guess
local function newCFrame()
if newElectronic.PrimaryPart ~= nil then
newElectronic:PivotTo(CFrame.new(Mouse.Hit.Position + newElectronic:GetExtentsSize() / 2) * newAngle)
end
end
Edit: The primarypart of the door does not cover the whole model, i’ve tried doing that using the boundingbox and that but it wasn’t even close to being better in terms of not clipping into other parts upon moving or rotating. I just want to be able to place models smoothly without them clipping into walls when dragging or with a large offset and I don’t know how to do this
Haha I fixed this pretty much to what I wanted it to be by just doing this
local function newCFrame()
if newElectronic.PrimaryPart ~= nil then
newElectronic:PivotTo(CFrame.new(Mouse.Hit.Position + Vector3.new(0,newElectronic:GetExtentsSize().Y / 2,0)) * newAngle)
end
end
It really took me this long to figure out that you don’t add all the x,y,z values, and only add the y when dealing with a model. Wow.