Created
July 28, 2012 11:00
-
-
Save namutaka/3192860 to your computer and use it in GitHub Desktop.
Unityではじめるゲームづくり Wiget_Camera.js 追尾型カメラの移動処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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