I need help with transitioning between 2 view angles. I've searched but couldn't find a solution for this.
I'm working on a board game with checkers-like pieces. I have the main camera mode set to perspective. When a piece needs to leave the game I have it so that it is dragged over to the bottom of the screen where I have a stack of all the pieces taken out at which point it should fly over and rotate to the correct place. The problem is that the stack is on another layer only viewed by a second camera in orthographic mode (the stack doesn't look right in perspective). I can switch layers on the piece but then it jumps to a different position on the screen (or off the screen) and its appeared rotation changes drastically.
I'd like to be able to adjust the piece's position and rotation so that it appears to not move or rotate as I change the layer.
Once it changes I can animate it to the correct position and rotation seamlessly. But that change over to orthographic is very jerky. Only solution I have is to do it off screen but it looks hackey. Is there a way to change perspectives but have the piece appear unchanged? Thanks
edit my setup is like so:
public class Stack : MonoBehaviour
{
[SerializeField] private Camera perspectiveCamera, orthogonalCamera;
[SerializeField] private Vector3 startPosition;
[SerializeField] private Vector3 startRotation;
[SerializeField] private float duration;
public void AddToStack(Transform piece)
{
piece.transform.SetParent(transform);
//here piece is where it is dropped. It is seen by the perspectiveCamera
//method sets new position and rotation of piece and sets piece.layer
ChangeOver(piece);
//here piece should be where it was dropped (no movement on screen) but it is seen by the orthogonalCamera
StartCoroutine(LerpBetweenPositionsAndRotations(piece));
}
private void ChangeOver(Transform piece)
{
//missing here: move piece in 3D without moving it on screen (have the new coordinates match from orthogonal perspective)
piece.position = //?
piece.rotation = //?
//set start position and rotation for IEnumerator
startPosition = piece.localPosition;
startRotation = piece.localRotation.eulerAngles;
//sets the piece to the stack layer only seen from orthogonalCamera
piece.gameObject.layer = gameObject.layer;
}
private IEnumerator LerpBetweenPositionsAndRotations(Transform piece)
{
for(float t = 0f; t < duration; t += Time.deltaTime)
{
piece.localPosition = Vector3.Lerp(startPosition, new Vector3(transform.childCount - 1, 0f, 0f), t / duration);
piece.localRotation = Vector3.Lerp(startRotation, Quaternion.Euler(0f, 0f, 0f), t / duration);
yield return null;
}
piece.localPosition = new Vector3(transform.childCount - 1, 0f, 0f);
piece.localRotation = Quaternion.Euler(0f, 0f, 0f);
}
this script is attached to my stack gameObject which is on layer only orthogonalCamera can see. I was looking for a way to fill in the first couple of code lines in the ChangeOver() method. (doesn't have to be done in 2 lines of course)
If I understand correctly you have two cameras always rendering, the one with the 3D perspective pieces and one for the already beaten pieces in orthographic.
Now you want to transition a piece from the perspective board into the stack but also transition from perspective to orthographic while/after it moves.
This sounds rather tricky to achieve tbh.
I can imagine a bit more complex solution using a third camera + additional dedicated transition layer
Camera.projectionMatrix)You probably could even combine the movement and projection fading in the same step to make the effect even cooler ^^
So something like maybe
This is untested (typed on a phone) but I hope that should at least get you started ;)
If you rather want to separate the movement of the piece from the transition you can do so of course and have separate loops.