Let me elaborate on the topic: I have a placement script ready, but I would like it so it would stick to a certain plot (or region). I did look at articles (especially this - Creating A Furniture Placement System by EgoMoose) but since it was OOP (Object Oriented Programming), I didn’t want to rewrite my script. I did look at the docs on world space to object space, but no luck.
Pretty simple script, was wondering if I can bound the object to a specific region or canvas.
Here is my script (this is a local script), controls the CFrame of the object:
function CalculatePosition()
CheckCollisions(model)
local x = math.floor(mouse.Hit.X / grid + 0.5) * grid
--local y = math.floor(mouse.Hit.Y / grid + 0.5) * grid
local y = 4
if y <= 4 then
y = 4
end
local z = math.floor(mouse.Hit.Z / grid + 0.5) * grid
if part then
model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame:Lerp(CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(rotation * rotationDegree),
0), speed))
end
end
If by bound you mean prevent the player from placing furniture outside of their plot, then you can just check if the furniture is outside of a certain area.
Ex. if furniture_x > X_Max or furniture_x < X_Min then
– prevent player from placing it
end
if you need to see the size of the object to determine if its crossing over, just subtract half of the X scale of the object from the X distance from the center (Furniture_x_pos - furniture_x_scale/2 )
If you need me to explain more, please let me know
-- First determine your bounds
local X_Max = 10
local X_Min = -10
local Y_Max = 10
local Y_Min = -10
-- Run this command when a player is trying to place furniture
local function moveblueprint(object_size,object_pos)
if object_pos.X + object_size.X/2 > X_Max or object_pos.X - object_size.X/2 < X_Min then
-- Prevent player from placing it
end
end
As shown with the top square, if we just got the pos of the object, its edges could go out of bounds
As shown with the bottom square, taking half of the scale of the object and adding it to its position allows for the edges of the square to remain in the bounds
You may have to tweak my code a bit to get it to work, trial and error is usually the best way to go
ok, thanks for the explanation, now I have another question: how would I find the max and min of the plot. Since the plot is a part, I can use the size, or do I need to add borders to the part and determine the position? Ask if I need to clarify.
I mean, you should make an outline of four parts, one for every value, and see where their positions lie. Or you could make it easier with some calculations.