Context: I have a 3d first person parkour game and have implemented wallrunning and wall climbing.
The issue is that you can still move the camera after starting the wallrun/climb. It would be better to fix the camera a bit to the direction you’re going in.
I want to make the Camera face towards a wall when climbing it. And fix the camera rotation to face the side of the wall respective to the normal when wallrunning.
Currently, for the wall climbing, I use look_at_from_position(Vector3.ZERO, climb_normal) and use the normal of the wall. However, getting the rotation on the Y axis doesn’t really seem to work.
It will usually not work though, and instead turns to the right/left of the wall. Adding/subtracting 90 degrees doesn’t work either because each wall has a different direction.
TL;DR
How do I get the look_at Y axis rotation and set the camera’s global_rotation.y to it?
If the camera is pitched up or down rotation y will not do what you want.
One way to go about this is add a camera arm and swivel hat is top level and has a remote transform telling it where to be positioned but not rotated. Then the camera can be a child of the arm/swivel and look at whatever, but if you need to rotate the camera, just rotate the parent y only.
There are more complicated maths ways to do it, but I find that adding arm and swivel nodes easier to manipulate.
Thanks, I got the answer.
Basically, you pass the normal to the function and use the PivotX variable where the PivotX is the same on from the hierarchy above.
func get_wallrun_rotation(_normal):
var old_rot = PivotX.rotation
PivotX.look_at(PivotX.global_position - _normal)
var new_rot = PivotX.rotation.y
PivotX.rotation = old_rot
return new_rot