I'm working on a Spider-Man like game and I've run into a problem. Whenever I'm near a wall and press the w key, the player starts climbing the wall. But when on the wall, I want it to face the direction of the input on the Z-axis only, such that, if I press ←, its head starts facing left, when I press →, it rotates toward right and so on.
I've tried everything to no avail. I should add that I'm average at math so I'm really bad at rotations and quaternions, etc.
Attaching links to videos of the movement on wall, how I want the player to rotate and here's the function I'm using to climb.
/// <summary>
/// Move player RB in the climbing state.
/// </summary>
/// <param name="moveDir"></param>
protected void ClimbMovementRB()
{
Vector3 inputVector = new Vector3(x: playerStateMachine.InputReader.HorizontalInput,
y: playerStateMachine.InputReader.VerticalInput, z: 0);
playerStateMachine.RB.velocity = playerStateMachine.transform
.TransformDirection(inputVector * playerStateMachine.PlayerProperties.ClimbSpeed);
playerStateMachine.PlayerModel.transform.rotation = Quaternion.Lerp(playerStateMachine.PlayerModel.transform.rotation,
Quaternion.LookRotation(inputVector, -playerStateMachine.transform.forward),
Time.deltaTime * playerStateMachine.PlayerProperties.RotationDamping);
DragControl();
ClimbSpeedControl();
}
The videos showing the problems.