Help on camera script

Hi I’m working on my first project is a fighting game such as street figther or mortal combat and so on.

I’m trying to calculate the distance between the player and the enemy and move the camera or field of view accordingly now I kind of did it but if I’m to far from the enemy or the player walks to far I’m out of the field of view so I can’t see the player.

Var targetA : Transform;
Var targetB : Transform;

Function Update()
{
var dist = Vector3.Distance(targetA, targetB);
Camera.fieldOfView = dist + 25;
}

So far this is the code that works looking both the player and the enemy but still when being far they are out of the field of view or camera view any help if you can?

Do they change the FOV in fighting game ? Don’t the camera go backwards instead (SSBB) ?

In this case you should go for Pythagorean theorem and the median.

I’m not sure changing the Field of View is the way to go.

I don’t remember those games, but maybe it would be easier to just move the camera back and forth so both players are on sight. Just make the sure the camera’s Far clip plane is large enough.

You can use FOV to create a “zoom” effect, but if the FOV gets too high (>60) you’ll start to see deformations on the image. And if it’s too low (<40) you’ll start loosing the depth of field (i.e.: everything will look flat instead of in 3D).

could you not do something like this
i’m going to use litteral words here because i cant be bothered think of the code but the basics of the algorithm are there

var playerA : Transform;
var playerb : Transform;
var minimum camera distance : float = 0.0;
var camera distance : float = 0.0;
var limited distance : float = 0.0;


function FixedUpdate ()
{
var abdistance = //calculate distance betwen player A and B;
// set camera distance transform algorithm here
if ( abdistance >= limited distance)
{
 camera distance = half abdistance;
}
else
{
camera distance = minimum camera distance;
}
}

Edit: i do realise that the person building the scene would posibly have to configure the minimum camera distance to work smoothly with with the limeted distance but with some clever maths i’d say minimum camera distance should be equal to half limited distance ie declare it within the function like this

var limeteddistance = minimumcameradistance*2;

and then the camera would pan out dependant on the players relative distance
8)

thanks for the help actually the reason why i used the field of view was my lack of knowledge i didn’t wanted the camera to move so far and through the level.

There’s some code and explanation for a fighting game camera in this thread if it’s any use.

Thanks for the help I will try the next thread about it.