How do i add arena limit to teleportion tool?

Hello everybody!

Im making a game with some skills, one of them is teleportion tool.
I’m using basic things, like when player uses tool it gets his mouse with Mouse.Hit.p, then teleports him in this place. The only thing is that it teleports him only in X and Z axis, he doesnt teleport in Y axis so he doesnt get under or above map. The problem is that he still can get out of map, so i would like to know how do i make it like that, so he can teleport only in bounding box of map model? If he tries to teleport out of map it will just teleport him to the edge of the map, like closest point he is allowed to teleport


if you didn’t get what i mean i tried to show what i’m talking about on this image

If you know how to achieve that, please help.

Note: the map edges are made out of invisible walls, and they all are in model so i can get their bounding box. Maybe i don’t really need it and i can do something with raycasting, but i’m not too good at raycasting and i don’t understand it well, so i’m not sure.

2 Likes

You could add a tag to parts that are allowable to be teleported and then check within script to see if the part you’re teleporting to is tagged with “teleportable” or something like that

When the player uses the teleport tool, first create an invisible, anchored, 1 by 1 by 1 part and set its CFrame to where the player clicked at (mouse hit position) and check if that part is inside the desired area (By using Spatial Query or use Region3 if you’re used to the old one.) and if the part is in the desired area, allow the player to teleport

The bounding box will work great here, and you can convert the player position to object space to determine where the bounds are. The area which is too far for the player would be half the size of the coordinate from center position along that coordinate axis of the bounding box. Using this fact, you can clamp the position of the x and z and then convert the position back to world space. It would look something like this:

local cFrame, size = mapWallModel:GetBoundingBox()
local objectSpacePosition = cFrame:PointToObjectSpace(teleportPosition)
local clampedX = math.clamp(objectSpacePosition.X, -size.X / 2, size.X / 2)
local clampedZ = math.clamp(objectSpacePosition.Z, -size.Z / 2, size.Z / 2)
local clampedTeleportPosition = Vector3.new(clampedX, objectSpacePosition.Y, clampedZ)
local newTeleportPosition = cFrame:PointToWorldSpace(clampedTeleportPosition)
2 Likes

Yea, such a simple way to fix that, but as i mentioned in the post, i just dont want player not to teleport, if he tries to teleport out of arena, it will teleport him to the allowed point (in arena, on the photo you can see that orange player tries to teleport to red point which is out of bounds of the map, so it teleports him to the blue point), which is exactly the problem. I don’t know how to do that

Thank you so much, it works great! For first testing i used script that spawns part, and if i were clicking out of bounds part were going to the edge of the map. The only problem is that bounding box makes it like that so it teleports not on the edge inside, but outside. So when player teleports he appears inside a wall and it can push him outside of arena. But i can easily fix that with another model with smaller walls which is made for teleportating, so player will be inside arena. Thank you so much again!

After little time i noticed that this method doesnt teleport you to the edge as on the photo, but actually teleports you to the closest point. But i don’t think it such a big problem, what i need is just keep players inside the arena, i said that just for note

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.