Detecting on which map the character is?

I personally use a math formula to determine this. It works with any funny angles your map may be at! Here’s roughly the checks I do:

  • Get a Hitbox of the map, If you don’t have one use Model:GetBoundingBox()
  • Get the HumanoidRootPart of the player, and ensure there is a HumanoidRootPart
  • Get the Local Difference by using the formula (Hitbox.CFrame - Hitbox.CFrame.p):inverse() * (HumanoidRootPart.Position - Hitbox.Position)
  • Check that the player is inside the Hitbox by doing checks on the X and Z axis of the Local Difference by doing math.abs(LocalDifference.X) < Hitbox.Size.X / 2

If both of those checks return true, the player is inside the box, otherwise they aren’t!

I run this in a Heartbeat loop.

4 Likes