Hey there! I am working on a wallrun system, and I want to be able to orient a player based on a raycast normal. The problem is, is that I just can’t figure this out. I keep getting the error "Argument 3 missing or nil" at the line that is supposed to orient the player.
When I apply it to the HumanoidRootPart like this:
while runService.RenderStepped:Wait() do
local _, y, z= CFrame.lookAt(humanoid.RootPart.Position, rayL.Position):ToOrientation()
local newCFrameLookAt = CFrame.fromOrientation(0,y,z)
humanoid.RootPart.CFrame = newCFrameLookAt
end
It just teleports me to the middle of the world. I also changed humanoid.RootPart.CFrame to humanoid.RootPart.Position.
Edit: Looks like I just forgot to do humanoid.RootPart.CFrame * newCFrameLookAt. But now there’s another problem, it spins me really fast.
So, I want to rotate the player when they are holding space against the wall. The player should rotate so they are looking 90 degrees away from the wall, for a wall run mechanic. I am checking if they are actually up against a wall by sending a raycast to the left and to the right of the player. I hope this is enough information.
CFrame.Angles() requires three parameters according to each axis of rotation.
raycast.Normal returns the direction facing away from the intersected surface.
You can find the vector parallel to the wall by taking the cross product between the up vector and the normal vector:
local direction = normal:Cross(Vector3.new(0, 1, 0))
You may need to negate this vector based on whether the character is running along a left or right handed wall.
Now you can create a rotation using CFrame.lookat()
local rotation = CFrame.lookat(Vector3.new(), direction * Vector3.new(1, 0, 1))
--we multiply the direction by (1, 0, 1) to ensure the rotation is exclusively along the xz plane and does not rotate the character facing up or down.
and now finally, apply the rotation to the RootPart.