Skip to content

Instantly share code, notes, and snippets.

@namutaka
Created July 28, 2012 11:00
Show Gist options
  • Save namutaka/3192860 to your computer and use it in GitHub Desktop.
Save namutaka/3192860 to your computer and use it in GitHub Desktop.
Unityではじめるゲームづくり Wiget_Camera.js 追尾型カメラの移動処理
function LateUpdate () {
if(!target) {
print("non");
return;
}
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentHeight = transform.position.y;
var currentDistanceZ = transform.position.z;
var currentDistanceX = transform.position.x;
var currentRotationAngle = transform.eulerAngles.y;
currentRotationAngle = Mathf.LerpAngle(
currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
var currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
var wantedDistanceZ = target.position.z - distance;
var wantedDistanceX = target.position.x - distance;
currentHeight = Mathf.Lerp(
currentHeight, wantedHeight, heightDamping * Time.deltaTime);
currentDistanceZ = Mathf.Lerp(
currentDistanceZ, wantedDistanceZ, distanceDampingZ * Time.deltaTime);
currentDistanceX = Mathf.Lerp(
currentDistanceX, wantedDistanceX, distanceDampingX * Time.deltaTime);
transform.position.x = currentDistanceX;
transform.position.z = currentDistanceZ;
transform.position.y = currentHeight;
LookAtMe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment