Using magnituide, how can I determine if a player is at least 70% in range based on the part’s area / size?
The Red Represents the part’s size, the Green is the 70% mark that I wish to detect using magnitude.
Basically, how can I use magnitude to do an if statement to detemine if the player is 70% inside that part.
Also a problem is I might not be able to use Magnitude, as that is a Circle.
if (char.HumanoidRootPart.Position - part.position).magnitude < [70% statement math] then
end
if (char.HumanoidRootPart.Position - Part.Position).magnitude < (Part.Size.X*0.7) then
This will only work properly if the part is square.
Also it will do it in a circular area from the centre of the part. You’ll need to do a lot more math to figure out if it’s inside the square area or use a different API.
I’ve done the math before and you just end up writing a rectangular prisim collision algorithm which already exists by adding a collider part. It’s even more redundant to use math, and much slower.
What you could try is getting the top right and bottom left corners of the shape and use their Y and Z coordinates, and then track the player’s position until their HumanoidRootPart’s position is within the two coordinates. Obviously this would be super laggy for if there’s a lot of parts in the game using this method, but with only one shouldn’t be too bad.
local relativePos = part.CFrame:pointToObjectSpace(humanoidRootPart.Position)
if math.abs(relativePos.X) <= part.Size.X * 0.7 * 0.5 and math.abs(relativePos.Z) <= part.Size.Z * 0.7 * 0.5 then
print("inside")
end
This will correctly handle rotated parts. You can also check the Y axis in exactly the same way if you want 3D checking, but your original question kind of implied you didn’t.