How to change movement of the character

Viewed 29

Hello everybody I have been trying to make a third person game for the first time. I have a problem with the movement. I want to give it a third person movement like in PUBG, or Control: when pressing A or D I want my charter to step slowly left or right but without turning his face.

With my current code, when I press A or D it turns its face and runs to that direction (as in the picture below).

How it moves currently:
how it moves currentlly

So how can I edit this code in order to make it as I mentioned above? Code:

stateMachine.transform.rotation = Quaternion.LookRotation(movement);
1 Answers

Throuth character model animation or "for" loop until stateMachine.transform.rotation == Quaternion.LookRotation(movement). Loop example:

  if ( Quaternion.LookRotation(movement) > stateMachine.transform.rotation){
    for (int x =stateMachine.transform.rotation; x < Quaternion.LookRotation(movement); x++){
    stateMachine.transform.rotation = x;
    }
    }
    else{
    for (int x =stateMachine.transform.rotation; x > Quaternion.LookRotation(movement); x--){
    stateMachine.transform.rotation = x;
    }
    }
Related