TCOP_playerCameraControl

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class MainCharacterController : MonoBehaviour {
    public float linealSpeed = 3f;
    public float rotationSpeed = 20f;
    private float directionModifier;

    void Start () {
        weightMultiplier = Mathf.FloorToInt(transform.GetComponent<Rigidbody> ().mass);
    }
    
    void Update () {
        //Detect if there is any movement input
        if (Mathf.Abs (Input.GetAxis ("Vertical")) > 0 || Mathf.Abs (Input.GetAxis ("Horizontal")) > 0) {
            transform.Translate (linealSpeed * Vector3.forward * Time.deltaTime);
        }

        //Rotation
        Vector3 input = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
        Vector3 inputRaw = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));

        if(Input.GetAxisRaw("Vertical") == 0 && Input.GetAxisRaw("Horizontal") == 0){
            directionModifier = cameraAngle();
        }

        //sqr length of vector & normalize
        if (input.sqrMagnitude > 1f) {
            input.Normalize ();
        }
        if (inputRaw.sqrMagnitude > 1f) {
            inputRaw.Normalize ();
        }

        if (inputRaw != Vector3.zero) { //If there is any input
            Vector3 targetRotation = Quaternion.LookRotation (input).eulerAngles; //y will contain the angle that we get from the normalizez input
            //we add the camera angle modifier (on Y) and rotate the character to the right direction at rotationSpeed
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(targetRotation.x, (Mathf.Round(targetRotation.y/45) * 45) + directionModifier, targetRotation.z), Time.deltaTime * rotationSpeed);
        }
    }

    float cameraAngle(){
        directionModifier = Camera.main.transform.eulerAngles.y;
        directionModifier = Mathf.RoundToInt(directionModifier / 90) * 90;

        return directionModifier;
    }
}