How can I make player's HRP face raycastResult.Position?

Currently have a wall climbing system. I’m wondering how I can make the player’s HRP face the raycastResult.Position without completely breaking my code. I’ve tried doing this:

hrp.CFrame = CFrame.lookat(raycastResult.Position, raycastResult.Position)

But that always results in my code completely breaking.
Is there something else I can do?
Any answers would be appreciated, thanks.

1 Like

I think the right way to use it should be:
hrp.CFrame = CFrame.lookAt(hrp.Position, raycastResult.Position)

1 Like
hrp.CFrame=CFrame.lookAt(hrp.Position,Vector3.new(raycastResult.Position.X,hrp.Position.Y,raycasyResult.Position.Z)

What @Dev_Peashie said has one problem and it’s that it will make the character look upwards incase the raycast is not on the same Y position, so you use the Hrp’s Y position instead

1 Like

Totally true, Im sorry for not even thinking about that. You are right.
But if all raycasts that surround player have its origin from the center of the HRP, I hardly think any of them could be in a different Y value, unless the rays are not in a 90° related with HRP. But yeah, possibly that happens in the case of OPs approach

1 Like

I just know this kind of thing because it has happened to me a few times in the past, i’d forget to otherwise.

Yeah if all raycasts are on 90 degree angle it wouldn’t matter but sometimes it’s good just the event of some unexpected case

1 Like

I applied this code. It worked! Although it worked, I was wondering how I could make it so that the player is perpendicular to the wall. Currently, if the player jumps onto the wall at an angle, they will be at an angle on the wall. What logic can I use to calculate a position perpendicular to the wall?

You should rotate the HRP.CFrame to match the Normals of the Raycast result too

image

That vector contains the rotation data of the face that is being hit by the raycast

My understanding is that the surface normal is a directional vector perpendicular to the surface that was hit. It has a magnitude and a direction, right? I tried to implement it into my code, but with no avail. Should I just be setting the player’s CFrame to its current CFrame times the Normal or is there something else?