The script is linked to the principle digicam.
On the high:
(Header("Digital camera Orbit"))
public bool orbitCamera = false;
public float rotationSpeed;
public Vector3 offset;
Then firstly ()
personal void Begin()
{
offset = new Vector3(participant.place.x, participant.place.y, participant.place.z);
}
And within the replace ()
personal void Replace()
{
if (orbitCamera)
{
remodel.eulerAngles += rotationSpeed * new Vector3(-Enter.GetAxis("Mouse Y"), Enter.GetAxis("Mouse X"), 0);
offset = Quaternion.AngleAxis(Enter.GetAxis("Mouse X") * rotationSpeed, Vector3.up) * offset;
remodel.place = participant.place + offset;
}
}
The issue is the displacement or one thing that in one other place the digicam too far in an ideal radio of the participant. I can rotate the digicam across the participant with the mouse and in addition transfer the digicam right down to the left with the mouse, the one thing with the half that rotates the digicam across the participant makes the place of the digicam removed from the participant.
How can I don’t change the gap between the digicam and the participant? It’s not that the digicam is within the participant, but when I begin the sport and the gap between the digicam and the participant is 4, then keep this distance and use the mouse to show across the participant to a radius of 4 distance.
Now the gap radius could be very far-off.
This can be a screenshot that reveals the digicam and distance from the participant when executing the sport:
However then, after I get to the compensation half in updating this half:
offset = Quaternion.AngleAxis(Enter.GetAxis("Mouse X") * rotationSpeed, Vector3.up) * offset;
remodel.place = participant.place + offset;
So this occurs:
I marked the participant with Purple Circle to indicate how fats is the participant’s digicam.
What I’m attempting to do the principle goal is to make use of the mouse to rotate the digicam right down to the left and in addition flip the digicam across the participant.
Technically it’s working, however I are not looking for the digicam to be too removed from the participant with the compensated half. I need to hold the gap from the digicam as it’s earlier than operating the sport.
The entire script:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class CameraController : MonoBehaviour
{
(Header("Digital camera Transitions"))
public bool startTransitions = false;
public bool waitBeforeStart = false;
public float transitionTimeToWait;
public Rework transitionTarget;
public float movementSpeed;
(Header("Observe/Look AT"))
public Rework observe;
public Rework lookAt;
(Header("Digital camera Orbit"))
public bool orbitCamera = false;
public float rotationSpeed;
(Header("Participant"))
public Rework participant;
public Vector3 offset;
personal void Begin()
{
offset = new Vector3(participant.place.x, participant.place.y, participant.place.z);
if (waitBeforeStart)
{
startTransitions = false;
StartCoroutine(TimeToStartTransition());
}
}
personal void Replace()
{
if (orbitCamera)
{
remodel.eulerAngles += rotationSpeed * new Vector3(-Enter.GetAxis("Mouse Y"), Enter.GetAxis("Mouse X"), 0);
offset = Quaternion.AngleAxis(Enter.GetAxis("Mouse X") * rotationSpeed, Vector3.up) * offset;
remodel.place = participant.place + offset;
}
if (startTransitions && transitionTarget != null)
{
remodel.place = Vector3.MoveTowards(remodel.place, transitionTarget.place, movementSpeed * Time.deltaTime);
if (remodel.place == transitionTarget.place)
{
remodel.gameObject.SetActive(false);
transitionTarget.gameObject.SetActive(true);
}
}
}
IEnumerator TimeToStartTransition()
{
yield return new WaitForSeconds(transitionTimeToWait);
startTransitions = true;
}
}