public void LerpTo(CameraView view) { targetView.name = view.name; targetView.useTransformPositionChanges = view.useTransformPositionChanges; targetView.ignoreLookRotationChanges = view.ignoreLookRotationChanges; targetView.rotationIsLocal = view.rotationIsLocal; targetView.positionLocalToLastTransform = view.positionLocalToLastTransform; if (view.useTransformPositionChanges) { targetView.target = view.target; } targetView.distance = view.distance; if (!view.ignoreLookRotationChanges) { view.ResolveLookRotationIfNeeded(); targetView.rotation = view.rotation; } StartLerpToTarget(); }
private void LerpToTarget() { lerping = true; long now = Proc.Time; long passed = now - started; float p = (float)passed / lerpDurationMs; if (now >= end) { p = 1; } if (!targetView.ignoreLookRotationChanges) { targetView.ResolveLookRotationIfNeeded(); if (targetView.rotationIsLocal) { Quaternion startQ = targetView.rotationIsLocal ? targetView.target.rotation : Quaternion.identity; Quaternion.Lerp(rotStart, targetView.rotation * startQ, p); } else { t.rotation = Quaternion.Lerp(rotStart, targetView.rotation, p); } } //Show.Log("asdfdsafdsa"); targetDistance = (targetView.distance - distStart) * p + distStart; if (targetView.useTransformPositionChanges) { if (targetView.target != null) { Quaternion rot = targetView.rotation * (targetView.rotationIsLocal ? targetView.target.rotation : Quaternion.identity); Vector3 targ = targetView.target.position; Vector3 dir = rot * Vector3.forward; RaycastHit hitInfo; if (clipAgainstWalls && Physics.Raycast(targ, -dir, out hitInfo, targetView.distance)) { distanceBecauseOfObstacle = hitInfo.distance; } else { distanceBecauseOfObstacle = targetView.distance; } Vector3 finalP = targ - dir * distanceBecauseOfObstacle; //Debug.Log(targetView.distance+" "+distanceBecauseOfObstacle+" "+targ+" "+targetView.target); t.position = Vector3.Lerp(startPosition, finalP, p); //Debug.Log("# "+p+" "+finalP); } else { t.position = Vector3.Lerp(startPosition, targetView.position, p); //Debug.Log("!" + p + " " + targetView.position); } } RecalculateRotation(); if (p < 1) { Proc.Delay(20, LerpToTarget); } else { if (targetView.useTransformPositionChanges) { _target = targetView.target; } lerping = false; } }