コード例 #1
0
        public void UpdateRotation()
        {
            float turningDirection = 0;

            if (Direction == ManeuverDirection.Right)
            {
                turningDirection = 1;
            }
            if (Direction == ManeuverDirection.Left)
            {
                turningDirection = -1;
            }

            Vector3 point_ShipStandBack  = Selection.ThisShip.GetCentralBackPoint();
            Vector3 point_ShipStandFront = Selection.ThisShip.GetCentralFrontPoint();
            float   pathToProcessLeft    = (MovementTemplates.CurrentTemplate.transform.InverseTransformPoint(point_ShipStandBack).x);

            if (pathToProcessLeft > 0)
            {
                float   distance_ShipStandFront_RulerStart  = Vector3.Distance(MovementTemplates.CurrentTemplate.transform.position, point_ShipStandFront);
                float   length_ShipStandFront_ShipStandBack = GetMovement1();
                Vector3 vector_RulerStart_ShipStandFront    = MovementTemplates.CurrentTemplate.transform.InverseTransformPoint(point_ShipStandFront);
                Vector3 vector_RulerStart_RulerBack         = Vector3.right; // Strange magic due to ruler's rotation

                float angle_ToShipFront_ToRulerBack = Vector3.Angle(vector_RulerStart_ShipStandFront, vector_RulerStart_RulerBack);

                float sinSecondAngle = (distance_ShipStandFront_RulerStart / length_ShipStandFront_ShipStandBack) * Mathf.Sin(angle_ToShipFront_ToRulerBack * Mathf.Deg2Rad);
                float secondAngle    = Mathf.Asin(sinSecondAngle) * Mathf.Rad2Deg;

                float angle_ToShipFront_CorrectStandPosition = -(180 - secondAngle - angle_ToShipFront_ToRulerBack);
                float rotationFix = angle_ToShipFront_CorrectStandPosition * turningDirection;
                Selection.ThisShip.SetRotationHelper2Angles(new Vector3(0, rotationFix, 0));

                Vector3 standOrientationVector = MovementTemplates.CurrentTemplate.transform.InverseTransformPoint(Selection.ThisShip.GetCentralFrontPoint()) - MovementTemplates.CurrentTemplate.transform.InverseTransformPoint(Selection.ThisShip.GetCentralBackPoint());
                float   angleBetweenMinus      = -Vector3.Angle(vector_RulerStart_ShipStandFront, standOrientationVector);
                float   angleFix = angleBetweenMinus * turningDirection;
                Selection.ThisShip.UpdateRotationHelperAngles(new Vector3(0, angleFix, 0));
            }

            MovementTemplates.AddRulerCenterPoint(point_ShipStandFront);
        }
コード例 #2
0
        private static void AddMovementTemplateCenterPoint(GameObject shipBase)
        {
            Vector3 point_ShipStandFront = shipBase.transform.TransformPoint(Vector3.zero);

            MovementTemplates.AddRulerCenterPoint(point_ShipStandFront);
        }