The camera does not follow the character UNITY 5

0

Unity Error

Look rotation viewing vector is zero
UnityEngine.Quaternion:LookRotation(Vector3

Full Code

    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
        public float speed = 6f;
        Vector3 movement;
        Animator anim;
        Rigidbody playerRidibody;
        int floorMask;
        float camRayLenght = 100f;
        private Vector3 playerToMause;


        void Awake()
        {
            floorMask = LayerMask.GetMask("Floor");

            anim = GetComponent<Animator>();
            playerRidibody = GetComponent<Rigidbody>();


        }
        void FixedUpdate()
        {
            float h = Input.GetAxisRaw("Horizontal");
            float v = Input.GetAxisRaw("Vertical");

            Move(h, v);
            Turning();
            Animating(h,v);

        }

        void Move(float h, float v)
        {
            movement.Set(h, 0f, v);
            movement = movement.normalized * speed * Time.deltaTime;

            playerRidibody.MovePosition(transform.position + movement);
        }
        void Turning()
        {
            Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit floorHit;

            if (Physics.Raycast(camRay, out floorHit, camRayLenght, floorMask))

            {
                Vector3 playerToMouse = floorHit.point - transform.position;
                playerToMouse.y = 0f;

Linha Erro  >>  Quaternion newRotation = Quaternion.LookRotation(playerToMause);

Linha Erro  >>  playerRidibody.MoveRotation(newRotation);

        }


    }


    void Animating(float h, float v)
    {

        bool Walking = h != 0f || v != 0f;
        anim.SetBool("IsWalking", Walking);


    }


}
    
asked by anonymous 23.04.2016 / 20:37

1 answer

1

Place a condition before LookRotation, for example:

if (playerToMouse != Vector3.zero)
    Quaternion newRotation = Quaternion.LookRotation(playerToMause);
    
28.04.2016 / 02:31