Fighting Game Camera Flipping
I'm making a fighting game camera which presents itself in 2D but allows characters to move in 3D (think Dead or Alive). This script works almost perfectly, however, when the character on the left side (primaryTarget) goes through the opponent to end up on the right side, the camera quickly flips perspective to show the other side of the characters, which is undesired.
Ideally the camera would stay on the same side of the characters and the fighter that was on the left would now be on the right, but it instead always tries to keep primaryTarget on the left.
Quaternion newRotation = Quaternion.identity;
Vector3 newPosition = Vector3.zero;
Vector3 midPoint = m_primaryTarget.transform.position + ( m_secondaryTarget.transform.position - m_primaryTarget.transform.position ) / 2;
newRotation = Quaternion.LookRotation ( midPoint - transform.position );
newRotation.eulerAngles += m_rotationOffset;
newPosition = midPoint + ( Quaternion.LookRotation ( m_secondaryTarget.transform.position - m_primaryTarget.transform.position ) * new Vector3 ( m_distance, 0, 0 ) + m_positionOffset );
transform.rotation = Quaternion.Lerp ( transform.rotation, newRotation, m_rotationDampening * Time.deltaTime );
transform.position = Vector3.Lerp ( transform.position, newPosition, m_positionDampening * Time.deltaTime );
Answer by JordyJS · Jul 10, 2016 at 01:36 PM
I believe I fixed it (famous last words). I ended up simply calculating the distance from the camera's current position to its new position, and if it was deemed too far, it would just swap the targets.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084534im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My 2D Android game(in unity) is not working 1 Answer
How can I PROPERLY keep a sprite on the camera boundaries? 0 Answers
How to add a frame to my camera view in the game view? 1 Answer
Text shows in scene but not in game,Text showing in scene but not in game 0 Answers
Sprite not visible in game mode,Sprite don't show in game mode 0 Answers