Hey. It’s February already can you believe it? Anyways.
My question or problem if you like, so I am making a battle royale game. And the barrier in my game functions like this:
Find the middle of the whole map:
local model = workspace.Model
local orientation = model:GetBoundingBox()
print(orientation)
Like this, but when you have some tall mountain around the map the Y value really gets a lot higher.
So… what’s the problem you ask?
And I answer:
On my map, there are different terrain levels. So you can stand on a tall building, or you can be deep down inside shrek’s nasty swamp.
Which leads me to this scientific and informative infographic:
Allow me to explain, the orange star and triangle represent 2 different players.
Black line in the middle, is the middle of the map where the barrier aims towards. And the red line is the barrier. The red circle in the middle is B A S I G L Y center/middle of the model/map. And I repeat: the middle of the map “Part”'s Y value is much higher since there are mountains around.
My script functions like this:
-
- Check the magnitude between center of map part and the player root part. (get the distance in studs)
-
- Get the barriers X size divided by 2 (radius of the barrier/ second grade math)
-
- If the distance/studs number is between center of map and player is bigger than the barrier radius.
It means that they are outside of the barrier.
- If the distance/studs number is between center of map and player is bigger than the barrier radius.
But that’s were the fun ends.
If you listened / read closely, I wrote this:
If the distance/studs number is between center of map and player is bigger than the barrier radius.
It means that they are outside of the barrier.
But that is the entire truth. Now, if we jump back to the picture again:
You can see that the “star” player is mathematically further away. But technically he is still in the zone, but the programming doesnt care about that. It basically measures that the distance of the “star” player is from the center is bigger than the radius of the barrier. Thinking that the “star” player is outside the barrier, it removes health from the player. Look at the green dotted lines, if you would straighten up that line it would be outside of the barrier. (just for informational purposes). And the triangle player which is higher up, hence, closer to the center of map is “Mathematically” closer, but the distance from player to barrier is the same as the star player.
I hope you get what I mean. So is there any way to measure the distance on an X or Y axis instead of taking the height into account, because both players are really the same lengts away from the barrier.
I really hope you get what I mean. All help is appreciated!
My current script:
while true do
for i, player in ipairs(game.Workspace.PlayersInGame:GetChildren()) do
if player then
local hrp = player:WaitForChild("HumanoidRootPart")
local positionFromMiddle = (hrp.Position-centerOffMap.Position).magnitude
if positionFromMiddle > BARRIER.Size.X/2 and #playersInGame:GetChildren() > 1 then
print(positionFromMiddle .. " position from middle")
print(BARRIER.Size.X/2 .. " barrier size")
player:WaitForChild("Humanoid"):TakeDamage(10)
end
end
end