So I am trying to implement a wallrunning mechanic into my game following this blog post/guide: Wall Running in Unity. After the developers basic implementation of wallrunning (the 7 first steps) he writes:
“In addition, I lock the player direction to forward along the wall while wall running (and then allow camera movement independently) to ensure wall checking is done consistently along the wall. In other words, even if the player looks away from their wall their ‘body’ is still perpendicular to it, and thus raycasts will be correctly sent towards it.”
He never mention how he did this though. So… how do you lock the transform rotation of your player so that the camera can move independently from the body? I have tried a lot of stuff but I am getting nowhere. This is probably really easy to do but I am new to Unity so please have patience with me
Help?
(I am using the standard Unity RigidBodyFPSController)
There actually isn’t a lock function per se. Anyone can set properties of a transform at any time.
If I had to guess, I think what he means is that he simply stops changing it and instead changes something else, either a separate transform (easiest) or he keeps track of the look direction separately and uses it for the camera, but not to drive the player’s rotation with those changing values, effectively “locking” it.
In order for something like this to work, it would require that the camera can’t be a child of the controller (and vice versa) right? Will I have to like create a separate gameobject (like an empty one) and then attach the camera and controller to that gameobject?
For example, if you want your camera to follow the player from a certain distance. You write a camera script that places the camera a certain distance from the player and points it to the player:
If the player movement code runs first and then the camera script runs, the camera finds the player and adjusts it’s position and direction accordingly. Then the camera is pointing to the player and a certain distance from the player when the frame is rendered. That’s what you want.
On the other hand, if the camera script runs first then the player script runs second- then when the frame is rendered the camera is pointing to (and a certain distance from) where the character used to be in the previous frame. Since the player’s movement amount varies from one frame to the next, then that means that the camera distance will also vary from frame-to-frame: The camera will appear to jiggle as your player moves.