I'm too dumb to make a Tekken-like camera, can someone help me with it?

I’m trying to make a game that is basically a Tekken clone, and I’ve spent three days on the camera. I have the movement and zooming in, but I can’t decide the direction it points in. I want to always be to side of the players, like this: 202314-pain.jpg

I’m to dumb to that though, I’ve tried at least 11 different solutions, and none of them work. If anyone knows what I’m doing wrong, could you help me fix it, maybe? Thanks :smiley:

(
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraZoom : MonoBehaviour
{
    public GameObject player1;
    public GameObject player2;
    public Vector3 offset;
    private Vector3 pos;
    public Transform test;
    public float zoom;
    private float comparison;
    public float divDist;
    public Vector3 center;
    
    public void LateUpdate()
    {
        pos = 0.5f * (player1.transform.position + player2.transform.position);

        float dist = Vector3.Distance(player1.transform.position, player2.transform.position);

         divDist = dist / zoom;

        test.position = pos;
        transform.position = pos;

        if(divDist < 0.5104699f)
        {
            divDist = 0.5104699f;
        }

        center = ((player2.transform.position - player1.transform.position) / 2.0f) + player1.transform.position;
        transform.LookAt(center);

        transform.position = (pos - offset * divDist);
    }
}
)

OK, forget everything you’ve done so far! You definitely want to use a Unity Package called Cinemachine but you have to install it first. Window > Package Manager > Unity Registry > Cinemachine

It’s going to take you a little while to get into it and I strongly recommend a good tutorial. learn.unity.com has some tutorials but they’re not as good as some independents on YouTube. Search there and find one that matches your skill level.

It may look like a heavy solution to your problem but you must use it. It will help you move the camera, keep characters in frame and avoid all those problems of rotation that you are probably finding now by manipulating the camera yourself.

One thing. If you watch an older tutorial (Cinemachine version 2.7.0 and older) you may struggle to find the Cinemachine menu. Since Cinemachine 2.7.1, it’s under the GameObject menu in the Unity Editor.