CameraFocusChanger.CameraFocusChanger.UpdateFocus C# (CSharp) Method

UpdateFocus() private method

private UpdateFocus ( ) : void
return void
        void UpdateFocus()
        {
            // do we have a target for the camera focus
            if (isFocusing)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Vector3d currentPosition = vessel.GetWorldPos3D();

                Vector3 targetPosition = targetTransform != null ? targetTransform.position : new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);

                Vector3 positionDifference = flightCamera.transform.parent.position - targetPosition;
                float distance = positionDifference.magnitude;

                //if (distance >= 0.015f)
                    //print(string.Format("Distance of {0}", distance));

                if (hasReachedTarget || distance < 0.015f)
                {
                    flightCamera.transform.parent.position = targetPosition;
                    hasReachedTarget = true;
                    isFocusing = targetTransform != null;
                }
                else
                {
                    //DebugPrint(string.Format("Moving by {0}", (positionDifference.normalized * Time.fixedDeltaTime * (distance * Math.Max(4 - distance, 1))).magnitude));
                    flightCamera.transform.parent.position -= positionDifference.normalized * Time.fixedDeltaTime * (distance * Math.Max(4 - distance, 1));
                    // if the parts are not of the same craft, boost the speed at which we move towards it
                    Part part = targetTransform != null ? Part.FromGO(targetTransform.gameObject) : null;
                    if ((part != null && part.vessel != vessel) || targetTransform == null)
                    {
                        flightCamera.transform.parent.position -= positionDifference.normalized * Time.fixedDeltaTime;
                        if (Time.time - startFocusTime > 10.0f)
                            hasReachedTarget = true;
                    }
                }
            }
        }