Pervent overlapping in x and z in a placement system

so i have a placement system, and it is using mouse.hit.position, the problem is, when i go onto walls, it has nothing to stop it half clipping through the wall,
Screenshot 2023-10-25 at 7.34.31 PM
for the ceiling it is even worse, because i added the extra half of the object to the object so the whole thing stays above ground.
Screenshot 2023-10-25 at 7.35.19 PM
code:

circle.Position = mouse.Hit.Position + Vector3.new(0,circle.Size.Y/2,0)

any idea how i can pervent this?

1 Like

First recommendation to raycast to the mouse position, like with bullet holes, you then change the CFrame the part based on the normal of the raycast, If it’s still clipping, you might wanna change from where the part pivots, so that you can get that difference to add to the position.

is it possible to use mouse.target surface? i heard that could maybe work

I’m gonna quote myself here:

hmm, the mesh i am doing is not complex at all, so i think this might work, i am not great at the math though, heres what i have so far:

if surface.Name == "Top" then
		pos = circle.Position + Vector3.new(circle.Size.Y)
--too lazy to do the rest but you get the idea
	elseif surface.Name == "Bottom" then
		pos = Vector3.new(0,-4,0)
	elseif surface.Name == "Front" then
		pos = Vector3.new(0,0,-4)
	elseif surface.Name == "Back" then
		pos = Vector3.new(0,0,4)
	elseif surface.Name == "Left" then
		pos = Vector3.new(-4,0,0)
	elseif surface.Name == "Right" then
		pos = Vector3.new(4,0,0)
	end

do you think this could work?

If anything is rotated (not aligned to any particular axis like in minecraft) then I’m afraid it won’t.

The surface is in objectspace and it needs to be transformed into worldspace.
Their offsets are in objectspace and they also need to be transformed into worldspace.

If you’re going to go through the hassle of fixing that, then you should just use raycasts to begin with. It’s much easier to do these kind of things with raycasts; don’t let it intimidate you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.