I wanna achive if part inside of a wall it should return to previous spot that it was not in wall
Example:
My part is here
I drag my part close to wall
I dragged my part inside of the wall
And when i try to drag inside of the wall or atleast mouse cursor i wanna return to or stick to this position
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalInput = require(script.Parent.Parent.LocalInput)
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Model = ReplicatedStorage:WaitForChild("Sellables").Structures.Part.Model
local gridSize = 0.5
--------------------------[[ Functions ]]--------------------------
function PrepareModel()
local NewModel = Model:Clone()
NewModel.Parent = workspace
local Highlight = Instance.new("Highlight", NewModel)
Highlight.Adornee = NewModel
Highlight.Name = "StructureHighlight"
for int, parts in ipairs(NewModel:GetChildren()) do
if parts:IsA("Part") then
parts.CanCollide = false
parts.CanTouch = false
parts.CanQuery = false
end
end
return NewModel
end
function ConvertToGridSize(mousePosition, HeightSize)
local newX = math.round(mousePosition.X / gridSize) * gridSize
local newZ = math.round(mousePosition.Z / gridSize) * gridSize
local newY = math.round(mousePosition.Y / gridSize) * gridSize
local newCframe = CFrame.new(newX, newY + (HeightSize / 2), newZ)
return newCframe
end
function MoveStructure()
local NewModel = PrepareModel()
local modelHeight = NewModel.PrimaryPart.Size.Y
while true do
local mousePosition = Mouse.Hit.Position
local NewCFrame = ConvertToGridSize(mousePosition, modelHeight)
NewModel:SetPrimaryPartCFrame(NewCFrame)
RunService.RenderStepped:Wait()
end
end
--------------------------[[ Inputs ]]--------------------------
LocalInput.moveStructure(MoveStructure)
How i do that? I don’t think with raycasts because i wanna place blocks top of it too!