Ohh I’ve done that, but doesn’t work like I want.
sorry if I can’t explain my self clear, English is not my native language… but I’ll try.
what I mean was …mmm … if you turn Right or Left (rotate Y axis) or Move (like a normal 3D person Character), the camera works perfect, and follows you fine.
but if you want to rotate Up or Down (because this is a space ship not a 3D person walkin character), the object Rotates but the camera don’t. it just don’t seems to care about other rotations on other axis except for “Y”.
like “ok I press RIGHT and the Ship turns RIGHT so I can see its Side, and then the camera smootly follows until it I see the Back of my ship again”
“but if I press DOWN my ship turns UP (this is ok is inverse control) so I can see the TOP of my ship, but my Camera stays in the same position, so I can see my ship pointing UP but the camera never moves to see the BACK of the ship again”
I’ve modified the smooth follow script and //Comented the parts where the code take in consider the Height, and added a few lines, and this Rotates Perfect! just like I want, BUT it doesn’t have Height (I comented those lines)… and what this does is that my space ship is ALWAYS at the CENTER of the Screen, making imposible to see “what i’m shooting at”.
I want the ship to be a litle lower on screen.
then if I add the empty G.O. above the ship it does some weird artifacts, like suddently the ship is upsidedown or not at the buttom of the scren, etc.
here is my code for my camera:
// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 0.5;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
wantedRotationAngle = target.eulerAngles.y;
wantedHeight = target.position.y + height;
wantedRotationAngleX = target.localEulerAngles.x;
wantedHeightX = target.position.x + height;
wantedRotationAngleZ = target.localEulerAngles.z;
wantedHeightZ = target.position.z + height;
currentRotationAngle = transform.eulerAngles.y;
currentHeight = transform.position.y;
currentRotationAngleX = transform.localEulerAngles.x;
currentHeightX = transform.position.x;
currentRotationAngleZ = transform.localEulerAngles.z;
currentHeightZ = transform.position.z;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentRotationAngleX = Mathf.LerpAngle (currentRotationAngleX, wantedRotationAngleX, rotationDamping * Time.deltaTime);
currentRotationAngleZ = Mathf.LerpAngle (currentRotationAngleZ, wantedRotationAngleZ, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
currentRotation = Quaternion.Euler (currentRotationAngleX, currentRotationAngle, currentRotationAngleZ); // 0, currentRotationAngle, 0
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
//transform.position -= target.transform.forward * distance;
// Set the height of the camera
//transform.position.y = height; /// QUIT THIS
// Always look at the target
//transform.LookAt (target);
//transform.LookAt(target, Vector3.down);
//Code so it always look at the same UP as the objective.
transform.LookAt(target, target.transform.up);
}
in this code almos at the buttom I have a few lines commented, the most important is the one that says “//QUIT THIS” (and the ones above and under that line)
if I turn “ON” those lines it behaves like I said “the ship is where i want but doesn’t rotate UP/DOWN”
if those lines are turned “OFF” then it behaves like “Following rotation OK, but the ship is at the perfect center of the screen”.
by reading the code I found it has a few lines like this:
wantedRotationAngle = “math stuff”
wantedRotationAngleX = “more math stuff”
wantedRotationAngleZ = “even more math stuff”
then it has more Math Stuff and finaly comes to this line:
currentRotation = Quaternion.Euler (currentRotationAngleX, currentRotationAngle, currentRotationAngleZ); // 0, currentRotationAngle, 0
by this I understand that
“currentRotationAngle”
even it doesn’t says “Y” it reffers to Y. then it calculates stuff based on a X-Z plane, and then it passes the calculated values to a variable
“currentRotation”
but as it says in the //Comment it passes
0 for X
value for Y
0 for Z
and Thats Exactly my problem!!, it just ignores every other rotation thats not on Y axis (Left Rigth)
but I’m not familiar with All that “Math Stuff” so I don’t know how to add code to do the same calculation it did for a X-Z plane but do it on a Y-Z plane.
Is this explanation more Clear?..