-
I want to achieve a system where you can detect when someone is beside the corner of a part.
-
I am bad at math and I don’t know how so could you guys explain to me what you would need to do.
Why not just check if the player is touching the part?
make a small part which is on the corner of that part and use that
I’m sorry but what if I have thousands of parts? I don’t want to make a part for every corner. I want the real way the real math to get the parts corner.
I am sorry but I don’t want to. I want to know whethere the player is at the corner not touching the part. its 2 different things
Surface Area
hmmmm… i wouldent know
yes I do need to learn math but I am quite horrible at it. If its so easy math could you help out?
Is it even achivalble in a roblox game liek has someoen done it before?
yes there are people who have done it before like for example in a parkour game. It detects whether someone is on the Ledge or not and makes him hold on and climb
Are they all going to be blocks? If so all you need to do is take the part sizes, find the part’s position, and find the 8 corners using those sizes. For example, if the bottom left front corner is at 0,0,0 and you know the size in the Z direction is 2, then you can find the top left front corner to be the same X and Y position but 2 studs up on the Z axis. And so on.
No u need to use vectors like
What you want to find that 3d corner? Let’s find out
Ooo I see. Know that’s what I’m talking about. Yes all the parts are going to be blocks.
I want to find the ledge which is the top edge of a part.
You can get the corners of the part by doing
local corner = part.CFrame * CFrame.new(part.Size.x/2, part.Size.y/2, part.Size.z/2)
or a shorter way is
local corner = part.CFrame * CFrame.new(part.Size * .5)
There are 8 corners of a cube. Those are:
local offset = part.Size * .5
local corner = part.CFrame * CFrame.new(offset)
local corner2 = part.CFrame * CFrame.new(-offset)
offset = Vector3.new(-offset.x, offset.y, offset.z)
local corner3 = part.CFrame * CFrame.new(offset)
local corner4 = part.CFrame * CFrame.new(-offset)
offset = Vector3.new(offset.x, offset.y, -offset.z)
local corner5 = part.CFrame * CFrame.new(offset)
local corner6 = part.CFrame * CFrame.new(-offset)
offset = Vector3.new(offset.x, -offset.y, offset.z)
local corner7 = part.CFrame * CFrame.new(offset)
local corner8 = part.CFrame * CFrame.new(-offset)
There’s probably better ways of getting corners but this is one atleast.
The way you would do it is probably the easiest by using region3. Since it is basically impossible to get directly on the edge of a part you can create a region3 where the edge is instead.
The maths is simple and understandable…compared to other things lol One way you can look at is is in 2d
If I have a box that is 4×4 then To region2 for the top right edge I would need to get the Position of the 2d square then 3.5,3.5 in object space to world and 4.5,4.5 in object space to world make a region between that and detct when the player enters the region.
Remember the formula to get the position of the edge of a box is
local P1 = Part.CFrame:PointToWorldSpace(Part.Size.X/2 - 2 ,Part.Size.Y/2- 2,Part.Size.Z/2)-- This is asuming you are looking for the right top Edge of the cube
local P2 = Part.CFrame:PointToWorldSpace(Part.Size.X/2 + 2 ,Part.Size.Y/2 + 2,Part.Size.Z/2) -- The region3 will have a radius of 2
Make a region3 with the points and you just have to check if the player is in the region3
I am using radius even though it is not a circle lol. Hopefully yknow what I mean.
Would that work if the cube is rotated? I am not sure it would.
yes it works when rotated.
Corner is a cframe though so if you want the position do corner.Position
awesome man. Thanks so much this was exactly what I was looking for. Well deserved that solution button.
I made this quick function to help you out.
Usage:
2021-12-22 19-29-56
My Code:
wait(2.5)
local function addCorners(v)
local newPart1 = Instance.new("Part", v)
newPart1.CFrame = v.CFrame * CFrame.new(0,v.Size.Y / 2,0)
newPart1.CFrame = newPart1.CFrame * CFrame.new(v.Size.X / 2, 0,0)
newPart1.Size = Vector3.new(1, 1,v.Size.Z)
newPart1.Anchored = true
local newPart2 = Instance.new("Part", v)
newPart2.CFrame = v.CFrame * CFrame.new(0,v.Size.Y / 2,0)
newPart2.CFrame = newPart2.CFrame * CFrame.new(-v.Size.X / 2, 0,0)
newPart2.Size = Vector3.new(1, 1,v.Size.Z)
newPart2.Anchored = true
local newPart3 = Instance.new("Part", v)
newPart3.CFrame = v.CFrame * CFrame.new(0,v.Size.Y / 2,0)
newPart3.CFrame = newPart3.CFrame * CFrame.new(0, 0,v.Size.Z / 2)
newPart3.Size = Vector3.new(v.Size.X, 1,1)
newPart3.Anchored = true
local newPart4 = Instance.new("Part", v)
newPart4.CFrame = v.CFrame * CFrame.new(0,v.Size.Y / 2,0)
newPart4.CFrame = newPart4.CFrame * CFrame.new(0,0,-v.Size.Z / 2)
newPart4.Size = Vector3.new(v.Size.X, 1,1)
newPart4.Anchored = true
end
for _,v in pairs(game.Workspace:WaitForChild("Buildings"):GetChildren()) do
if v:IsA("Part") then
addCorners(v)
end
end
game.Workspace.Buildings.ChildAdded:Connect(function(v)
addCorners(v)
end)
There are most likely easier ways to do this however this is just a quick method I made for you.