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);
}
}