# How do you determine the distance of a player to any side/area of a part, and not just from the middle of it?

I’m adding water sounds to play by my terrain water using invisible parts and it only works well in some areas, because in other areas the middle of the part is too far away to be heard. Is there a way to use magnitude or calculations to find the distance of a player to the closest side/area of a part, and not from its middle?

For example, if a player was closest to a part’s left side, then I could calculate the distance from the player’s root to that side, and not from the player’s root to the part’s middle.

If I understood your problem correctly, your solution would be to stick to calculating the magnitude but to also consider the region size by subtracting half it from your magnitude when comparing it to other regions. The result would be the true closest region in which you can play your audio from.

You can just calculate if the player is inside of it
By doing this:

``````if c.Position.x - v.Position.x <= v.Size.X/2 and c.Position.x - v.Position.x >= v.Size.X/-2 and c.Position.z - v.Position.z <= v.Size.z/2 and c.Position.z - v.Position.z >= v.Size.z/-2 then
``````

C would be the part of region, and v the root part

Alright I’ll try this out and give you some results