I’m making a fighting game on a side scrolling view and it’s not orthograpich it’s 3d the camera.
my problem is that when both the player get close the camera zooms in too much close, and when both of the player and enemy are far apart from each other the camera moves way to far out of the level.
my question would be how to control this behavior?
here’s the code, all you need is two objects one player and one enemy i got this code from the forums and i fixed it a bit to work but not good enough as of yet.
Code:
//targets to be added, a for enemy and b for player depending where are they located.
var a : Transform;
var b : Transform;
// this code is irrevelant for testing the gui
function OnGUI()
{
GUI.Box ( Rect(10, 10, 100,90), “debugging”);
}
function Update ()
{
//calculations for the camera…
var abHeading : Vector3 = b.position - a.position;
var perp : Vector3 = Vector3.Cross(abHeading, Vector3.up);
var halfway : Vector3 = (a.position + b.position) /2;
var dist : float = Vector3.Distance(a.position, b.position);
var distScale: float = 2.0;
//////////////
halfway.y = 2.0;
///moving the camera the if statement makes the camera invert the code so it stays on the same asxis
camera.transform.position = halfway + perp.normalized * dist * distScale;
if(abHeading.x > 0)
{
camera.transform.position = halfway - perp.normalized * dist * distScale;
}
///////////////////////
//print(dist);
//print(abHeading);
//print(perp);
//print(halfway);
//print(distScale);
}