I used to be following a unity tutorial to make my character face within the place the digital camera is dealing with. After I completed the modifying the script, I bought an error at runtime saying, “Look rotation viewing vector is zero.” On the road :
Vector3 viewDir = participant.place - new Vector3(rework.place.x, participant.place.y, rework.place.z);
orientation.ahead = viewDir.normalized;
right here is the remainder of the code I wrote:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class ThirdPersonCam : MonoBehaviour
{
[Header("References")]
public Remodel orientation;
public Remodel participant;
public Remodel playerObj;
public Rigidbody rb;
public float rotationSpeed;
personal void Begin()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.seen = false;
}
void FixedUpdate()
{
Vector3 viewDir = participant.place - new Vector3(rework.place.x, participant.place.y, rework.place.z);
orientation.ahead = viewDir.normalized;
// rotate the playerObj
float horizontalInput = Enter.GetAxis("Horizontal");
float verticalInput = Enter.GetAxis("Vertical");
Vector3 inputDir = orientation.ahead * verticalInput - orientation.proper * horizontalInput;
if(inputDir != Vector3.zero)
playerObj.ahead = Vector3.Slerp(playerObj.ahead, inputDir.normalized, Time.deltaTime * rotationSpeed);
}
}