Hello everyone! I’m trying to make a grid placement system where a player clicks a button to place an object and rotate, delete it, other factors too etc. I also have a currency system and I want to make it so when the player puts down the furniture, it takes their money away. I’ve followed countless tutorials but most of them are all outdated :,) . How could I achieve this?
Im not going to make the whole thing for you, but I can provide a function that rounds the objects position to a grid, just to get you started?
local function snapToGrid(position)
local snappedX = math.floor(position.X / 2 + 0.5) * 2
local snappedY = math.floor(position.Y / 2 + 0.5) * 2
local snappedZ = math.floor(position.Z / 2 + 0.5) * 2
return Vector3.new(snappedX, snappedY, snappedZ)
end
Then from here you have to get the Players Mouse Position in 3D space. I have also made a function for that(best way imo):
local UserInputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
function returnMousePosIn3DSpace() : Vector3
local MouseLocation = UserInputService:GetMouseLocation()
local MousePositionin3D = Camera:ScreenPointToRay(MouseLocation.X, MouseLocation.Y)
return MousePositionin3D.Direction
end
Here are 2 basic starting blocks for your building system, now you have to customise and make your own version with furniture, cash, and removing.
3 Likes