camera追従について
Posted: 2013年10月14日(月) 10:48
playerのうしろを追従するプログラムを組んでいるのですが、Y軸だけでなくXとZ軸のplayer回転にも対応させたい。
で、組んだのがこれ。
やっぱりうまくいかない。
どなたかわかる人いましたら、よろしくお願いいたします。
で、組んだのがこれ。
var target : Transform;
// The distance in the x-z plane to the target
var distance = 30.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
// Place the script in the Camera-Control group in the component menu
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngle_x = target.localEulerAngles.x;
//var wantedHeight_x = target.position.x + height;
var wantedRotationAngle_y = target.localEulerAngles.y;
//var wantedHeight_y = target.position.y + height;
var wantedRotationAngle_z = target.localEulerAngles.z;
//var wantedHeight_z = target.position.z + height;
var currentRotationAngle_x = transform.localEulerAngles.x;
//var currentHeight_x = transform.position.x;
var currentRotationAngle_y = transform.localEulerAngles.y;
//var currentHeight_y = transform.position.y;
var currentRotationAngle_z = transform.localEulerAngles.z;
//var currentHeight_z = transform.position.z;
// Damp the rotation around the y-axis
currentRotationAngle_x = Mathf.LerpAngle (currentRotationAngle_x, wantedRotationAngle_x, rotationDamping * Time.deltaTime);
currentRotationAngle_y = Mathf.LerpAngle (currentRotationAngle_y, wantedRotationAngle_y, rotationDamping * Time.deltaTime);
currentRotationAngle_z = Mathf.LerpAngle (currentRotationAngle_z, wantedRotationAngle_z, rotationDamping * Time.deltaTime);
// Damp the height
//currentHeight_x = Mathf.Lerp(currentHeight_x, wantedHeight_x, heightDamping * Time.deltaTime);
//currentHeight_y = Mathf.Lerp(currentHeight_y, wantedHeight_y, heightDamping * Time.deltaTime);
//currentHeight_z = Mathf.Lerp(currentHeight_z, wantedHeight_z, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler(currentRotationAngle_x, currentRotationAngle_y,currentRotationAngle_z);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
//if(target.rotation.y)
//transform.Rotate(target.localEulerAngles.x,target.localEulerAngles.y,target.localEulerAngles.z);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
//transform.position.y = currentHeight_y;
// Always look at the target
transform.LookAt (target);
}
どなたかわかる人いましたら、よろしくお願いいたします。