In advance, thank you andeeee for the help with the camera before, however there is ONE last thing that has been frustrating me and the whole class :x
Our class has swapped to a 2d plane as opposed to 3d.
Ok so as our camera is now, if one character goes below/above the other the camera completely flips perspective to the other side, is there a way to keep it on one side and one side only so it doesn’t flip perspective?
Also now that we have switched to a 2d plane the camera no longer zooms in or out to match the halfway point and display both items at the same time, however horizontally it will follow the half waypoint to a certain extent, once the objects get too far from one another it stops moving as it tries to view both objects at the same time.
var target : Transform;
var target2 : Transform;
function LateUpdate () {
var targetsHeading: Vector3 = target2.position - target.position;
var perp: Vector3 = Vector3.Cross(targetsHeading, Vector3.up);
var halfway: Vector3 = (target.position + target2.position) * 0.5;
var dist: float = Vector3.Distance(target.position, target2.position);
var distScale: float = -.25;
var camHeight : float = 2;
var minDistance: float = -10;
camera.transform.position = halfway + perp.normalized * (dist * distScale + minDistance) + Vector3.up * camHeight;
transform.LookAt(halfway);
}
function Start () {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
Unfortunately, there is no cross product for two-dimensional vectors, it only makes sense in three dimensions (although someone will doubtless chirp up and mention that there is a very useful seven-dimensional version as well )
On the upside, you don’t need the cross product when the action takes place in a 2D plane. As before, the distance of the camera is proportional to the distance between the players, but this distance is measured away from the plane in which the action takes place. Say, for example, the players move in the XY plane (ie, the Z coordinate is always zero). Rather than use the cross product to get the camera perpendicular, you just need to take the average of the players’ positions (ie, the centre point between them):-
var midPt: Vector3 = (player1.position + player2.position) / 2.0;
…and then take that point and set its Z coordinate to the desired distance, calculated as before:-
midPt.z = <distance proportional to distance between players...>
Thx, i’ll give that a shot, and what about making it so that the camera doesn’t flip perspective when one target changes the side from the other? Is there any way to fix that?
Currently what happens is it starts out on Side A
Target1 and Target2 are at their starting points
When Target 1 and Target 2 switch sides the camera flips perspective to Side B, but the controls remain the same.
So where as normally, on Side A, pressing D would make it go in the direction it appears, (to the right)
But when you pass the other target, it swaps sides, and the controls stay the same, so when you press D, it appears that you are walking to the Left, but you are still walking in the same direction.
Since the action takes place in a single plane, this won’t happen at all. The camera’s position only relies on the midpoint and this is the same regardless of which way round the players are standing.
nevermind on the where would the midPt.z go, i got that, now my only problem is that it’s not rotating out to the side view. it’s attempting to use an overhead view.
ok, so i got the camera almost perfect, but i still cannot get it to be at a direct right or left to the platform, it is at an angle, unlike before we moved to the 2d plane. this is what i have for the code, after countless tweaking for perp, midPt and targetsHeading is a must.
var target : Transform;
var target2 : Transform;
function LateUpdate () {
var targetsHeading: Vector3 = target2.position - target.position;
var halfway: Vector3 = (target.position + target2.position) * 0.5;
var midPt: Vector3 = (target.position + target2.position) / 2.0;
midPt.z = 50;
var perp: Vector3 = targetsHeading - midPt;
var dist: float = Vector3.Distance(target.position, target2.position);
var distScale: float = 1;
var camHeight : float = 5;
var minDistance: float = 10;
camera.transform.position = halfway + perp.normalized * (dist * distScale + minDistance) + Vector3.up * camHeight;
transform.LookAt(halfway);
}
function Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
will edit and supply screenshot
#1
#2
looking for it not to angle as it does in the first pic.