Finding the Position on a Part's surface

I’m currently trying to make a player teleport to a fixed position where you face the wall at a specific position on a part’s surface, sorta like the screenshot below.

image

the thing is, I have no idea how to do this. what I am trying to achieve is a wall combo system similar to most battlegrounds games. my goal is to make the player be in the same position as shown in the screenshot above by only knowing the player’s CFrame and the part. this is very tricky because you need to know which surface, and where on the surface.

if you have any questions or need more clarification, I’d be more than happy to answer.
pls help :pleading_face: :pleading_face:

2 Likes

I don’t fully understand what it’s asking. Do you mean like “click on a pos on the wall, then tp there” or something similar to that?

If so, you can use a raycast and get the hit position.

1 Like

The best way is to get the size of the wall and use that to find the position you want your player to be in. Position and Size are both Vector3, and both use the same distance measurement, so you should be able to position a player relative to the wall size. Infact, by what the picture shows, you only need to use the x or z compentent of the wall size (depending on the walls rotation), if im correct I think you divide the size by 2 and add it to your players position (not completely sure on it though)

1 Like

You can use Workspace’s Raycast method in order to both return a part, the position vector of where the part was returned and also the surface normal vector, which will give you the information needed to align your character accordingly.

2 Likes

You can just raycast backward from the HumanoidRootPart. It will return that position on the wall.

1 Like

sorry everyone for not answering sooner. what I mean is that if I have a hitbox checking for any walls and it detects one, then I need to find what side of the part is closest AND what position on that side is also closest. you would know what I mean if you’ve seen wall combos on plenty of battlegrounds games, particularly The Strongest Battlegrounds.

I don’t want to use Raycasts because I don’t want to have to create multiple Raycasts in different directions just to find a wall. even if I did do that, I would have a problem if multiple Raycasts hit the same part.

so if you only knew the Part’s CFrame and the player’s CFrame, how should you go about doing this? if you really do need to use raycasts, let me know. here’s a preview of what I want to achieve:

you can see that you get anchored at a specific spot on the wall’s surface. also, I want this to work on any orientation. thanks!