Hello, I’m currently stuck with figuring out how to make a function do something properly. The
Plot has a
Plot.Base part inside of it, and I want the
Object to be within the X and Z bounds of the
Currently, the code works fine for stuff that isn’t rotated, but the code doesn’t properly account for rotation. Along with that, parts could be resized so it has to account for size, position, and rotation all at the same time. I’m pretty bad with math, so I’m not really sure what I’m doing. I can’t find anything similar to my problem which would be good for this use.
Example of what I want to happen, even if the part has rotation:
Current code which doesn’t work correctly:
local function checkIfPartIsInBounds(Part, Base)
local partPos = Part.Position
local partSize = Part.Size
local basePos = Base.Position
local baseSize = Base.Size
-- Calculate the boundaries of the base part in the X and Z directions
local minX = basePos.X - baseSize.X/2
local maxX = basePos.X + baseSize.X/2
local minZ = basePos.Z - baseSize.Z/2
local maxZ = basePos.Z + baseSize.Z/2
-- Check if the part is within the X and Z boundaries of the base part
if partPos.X - partSize.X/2 >= minX and partPos.X + partSize.X/2 <= maxX and
partPos.Z - partSize.Z/2 >= minZ and partPos.Z + partSize.Z/2 <= maxZ then
Other function I tried which also doesn’t work:
local function testcheck2(Player, NewObject)
local Plot = GetPlotFromPlayer(Player)
local halfSizeX = NewObject.Size.X / 2
local halfSizeZ = NewObject.Size.Z / 2
local basePosX = Plot.Base.Position.X
local basePosZ = Plot.Base.Position.Z
local baseSizeX = Plot.Base.Size.X / 2
local baseSizeZ = Plot.Base.Size.Z / 2
local partPosX = NewObject.Position.X
local partPosZ = NewObject.Position.Z
if partPosX - halfSizeX < basePosX - baseSizeX or partPosX + halfSizeX > basePosX + baseSizeX or
partPosZ - halfSizeZ < basePosZ - baseSizeZ or partPosZ + halfSizeZ > basePosZ + baseSizeZ then
Any help with this problem would be much appreciated!
try storing the rotation as a
local in the code, and constantly update it like this (example)
local partRot = script.Parent.Orientation
local courotine5 = coroutine.wrap(function()
local partRot = script.Parent.Orientation
the above orientation will be according to the world
then have the code account for the orientation in some way
The problem isn’t getting the orientation, it is that I don’t know how to actually account for it. I’m not good at 3D world space math.
put a hitbox around the part, and if the hitbox collides with the wall, reset the part
the hitbox can be a square that surrounds the part, and maybe more in some directions, and have it move with the part
you can update the hitbox’s position like this:
local coroutine5 = coroutine.wrap(function()
hitbox.Position == newObject.Position
and loop the coroutine to keep moving the hitbox’s position, and instead of using the part for detection, use the hitbox
There are no walls. The object is meant to be placed upon a base, and if any point of the part is outside of the base it should return false, even if it is rotated. X and Y in scale mean different things when the object is rotated, so I’m not sure how to compensate for that.
try adding invisible walls that have like almost infinitely small scaling except for Y, for hit detection
I don’t want to use hit detection, I just want a function that does math to figure out if the object is within the bounds of the base. It would be more convoluted to have to set up hit detection and intersection stuff. It would be a lot cleaner for the function to just use math. All it needs is to account for rotation, it’s already gotten far enough to do position and scale. It just can’t account for rotation yet.
Here is a video of the issue. With the first slope which is at it’s default rotation, you can see that it has no trouble being scaled correctly at neutral rotation. The server code properly denies it from being scaled out of bounds.
However, with the second slope I place, you can see that it gets improperly denied when it should be fine. This is because the slope is rotated, and the function does not account for rotation. I’m not sure how to make it account for rotation.
check the parts rotations, and if the part is rotated differently, account differently for the scale, like offset the bounds check or something