Hello fellow developers,
I have been starting to work on this project just for fun because I’ve seen games like a retail tycoon and wondered if I could do something like that. I have different places you can own and when you click B or click the UI button you go into “build mode” (Shown here):
In “build mode” you choose a part (for now it defaults to Robloxes default part) and this part appears at your cursor. A function is bound to renderstepped that moves the part in front of your cursor (only the raycasting part will be shown):
local rayResult = workspace:Raycast(origin.Origin, origin.Direction * 1000, params)
if rayResult then
if rayResult.Instance.Parent:GetAttribute("Owner") then
if rayResult.Instance.Parent:GetAttribute("Owner") == plr.Name then
Building.CurrentItem.Color = Color3.fromRGB(0, 255, 0)
Building.CanBuild = true
else
Building.CurrentItem.Color = Color3.fromRGB(255, 0, 4)
Building.CanBuild = false
end
else
Building.CurrentItem.Color = Color3.fromRGB(255, 0, 4)
Building.CanBuild = false
end
Building.CurrentItem.Position = rayResult.Position
end
As you can see the current part that we are editing is put to the raycasting position, which does not account for overlapping of parts:
Things I have thought about so far are looping through everything in the workspace, and checking if every stud of the currently looped part from the middle outward is in the same place as one of the studs of the part being moved. This seems really expensive though. Sorry if I am just being stupid and there is a built-in feature. I have also thought about using the .Touched event, but I have no idea how you would implement that. Thank you for your help!