How To Align A Part to a wall that is orientated

I want to make align a part with a wall when I hit the ray cast and Idk how here’s what a script that just makes the person look at the wall and be on the wall but I don’t know how to orientation the character if the player goes up and down.

HRP.CFrame = CFrame.new(HRP.CFrame.p,Vector3.new(HRP.Position.X - Normal.x,HRP.Position.Y,HRP.Position.Z - Normal.z)) 
bodygyro.CFrame = CFrame.new(HRP.CFrame.p,Vector3.new(HRP.Position.X - Normal.x,HRP.Position.Y,HRP.Position.Z - Normal.z))

Sorry but, any more information on exactly what you want? Like a contextual use-case scenario like for example wall climbing or a wall stick mechanism.

Wall climbing and that’s what’s get them on on the wall

What do you mean by orientating the character when climbing up?

Yep, I’m confused on what orientation means in this scenario as well, forgot to ask about that thanks.

A gif or video showing the problem will be really helpful as well.

However for the code given I recommend splitting it up into seperate variables and using the new CFrame.lookAt constructor

local currentPlayerPos = HRP.CFrame.Position
local surfaceNormal = Normal
local lookAt = currentPlayerPos-surfaceNormal

HRP.CFrame = CFrame.lookAt(currentPlayerPos, lookAt) 
bodygyro.CFrame = CFrame.new(currentPlayerPos, lookAt)

this should make the player look at a point towards the wall from the player’s position.

1 Like

Don’t Worry about the Animation but here sorry that I have given it earlier.
robloxapp-20201020-1120076.wmv (1.0 MB)

Would you mind converting that to a file type that will embed so that I don’t have to download it (for safety’s sake)?

Yeah, I recommend using imgur since it embeds automatically onto Discourse unlike streamable. I did it for you lol:

Anyways the problem with the original code is that the CFrame only orientates in the XZ plane. As seen in the vector 3 construction for the CFrame.new() parameter for the look at the position below:

Try using this below which should make the player look towards the wall via vector maths with the surface normal and the player position which I gave above a well.

1 Like