The script is connected to the Most important Digital camera.
On the prime :
[Header("Camera Orbit")]
public bool orbitCamera = false;
public float rotationSpeed;
public Vector3 offset;
Then within the Begin()
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 offset or one thing e else place the digicam too far in a giant radius from the participant. I can rotate the digicam across the participant with the mouse and likewise transfer the digicam up down left proper throughout with the mouse the one thing with the half that rotates the digicam across the participant make the digicam place to be very removed from the participant.
How can I make that it’s going to not change the space between the digicam and the participant? Not that the digicam can be on the participant but when I begin the sport and the space between the digicam and the participant is 4 then preserve this distance and use the mouse to rotate across the participant at a 4 distance radius.
Now the space radius may be very very far.
This can be a screenshot exhibiting the digicam and the participant distance when working the sport :
however then when it is attending to the offset half within the Replace this half :
offset = Quaternion.AngleAxis(Enter.GetAxis("Mouse X") * rotationSpeed, Vector3.up) * offset;
remodel.place = participant.place + offset;
Then this occurs :
I marked with purple circle the participant to point out how fats the digicam is from the participant.
What I am attempting to do the primary objective is to have the ability to use the mouse to rotate the digicam up down left proper and likewise to rotate the digicam across the participant.
Technically it is working however I do not need the digicam to be too removed from the participant with the offset half I need to preserve the space from the digicam as it’s earlier than working the sport.
The total script :
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class CameraController : MonoBehaviour
{
[Header("Camera Transitions")]
public bool startTransitions = false;
public bool waitBeforeStart = false;
public float transitionTimeToWait;
public Remodel transitionTarget;
public float movementSpeed;
[Header("Follow/Look AT")]
public Remodel comply with;
public Remodel lookAt;
[Header("Camera Orbit")]
public bool orbitCamera = false;
public float rotationSpeed;
[Header("Player")]
public Remodel 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;
}
}