How to make a placement system have block collisions?
Hello! I've been recently working in a block placement system using mouse.Hit
, and I'm stuck with a problem; I don't know how to make the blocks not go through others.
This is the code I have:
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local runservice = game:GetService( "RunService" ) |
04 | local ts = game:GetService( "TweenService" ) |
07 | local part = Instance.new( "Part" , workspace) |
08 | part.Size = Vector 3. new( 4 , 4 , 4 ) |
10 | mouse.TargetFilter = part |
11 | part.CanCollide = false |
13 | part.Material = Enum.Material.SmoothPlastic |
15 | mouse.Move:Connect( function () |
16 | local target = mouse.Hit |
17 | local Ypart = mouse.Target |
18 | local face = mouse.TargetSurface |
19 | if target and Ypart then |
20 | ts:Create(part, TweenInfo.new( 0.1 , Enum.EasingStyle.Sine), { Position = Vector 3. new(math.floor(target.Position.X + 0.5 ) - part.Size.X/ 2 , math.floor(target.Position.Y) + part.Size.Y/ 2 , math.floor(target.Position.Z + 0.5 )- part.Size.Z/ 2 ) } ):Play() |
I don't really know how to explain, but when you try to place a block on a wall, the block goes inside the wall and it does z-fighting. The thing I'm trying to do is making the blocks not collide with each other while being placed.