I want the camera to shift from a top-down camera for the game to a side view during the actual attack. I am using Cinemachine & I have two cameras made. They are successfully transitioning between the two.
Where I am struggling is how to position the camera properly. Here is what I have so far:
[SerializeField] private GameObject actionCameraGameObject;
[SerializeField] private GameObject cameraTestObject;
Unit shooterUnit = shootAction.GetUnit();
Unit targetUnit = shootAction.GetTargetUnit();
//I don't think I need this line anymore?
Vector3 shootDir = (targetUnit.GetWorldPosition() - shooterUnit.GetWorldPosition()).normalized;
//This code find the midpoint (x & z) between the two units
Vector3 center = (shooterUnit.GetWorldPosition() + targetUnit.GetWorldPosition())/2f;
//This is to rotate the camera, but isn't quite working. I think it is what I am multiplying it by that is causing issuess?
Vector3 shoulderOffset = Quaternion.Euler(0,90,0) * center;
//This code declares how high the camera should be
Vector3 cameraCharacterHeight = Vector3.up * heightOfCamera;
//This is defining the camera location
Vector3 actionCameraPosition = center + shoulderOffset + cameraCharacterHeight;
//This is moving the camera to the correct position
actionCameraGameObject.transform.position = (actionCameraPosition);
//This is rotating the camera to the correct location
actionCameraGameObject.transform.LookAt(center);
//I am using this to visualize where the camera was placed...this will be deleted later
Instantiate(cameraTestObject, actionCameraPosition, Quaternion.identity);
If I remove the rotation line, it places the camera perfectly between the two characters, but I need something in there so that the camera:
-
Is rotated from a side view, as opposed to a top view
-
Is far enough back so that both units are visible.
Any suggestions?