Beispiel #1
0
        private void Reset()
        {
            if (RigidBody == null)
            {
                Debug.LogError("Component: TrackWheel requires RigidBody component.", this);
            }
            else
            {
                Radius = Tire.FindRadius(RigidBody, true);
                m_frame.SetParent(RigidBody.gameObject);

                // Up is z.
                var upVector = RigidBody.transform.parent != null?
                               RigidBody.transform.parent.TransformDirection(Vector3.up) :
                                   Vector3.up;

                var rotationAxis = Tire.FindRotationAxisWorld(RigidBody);
                m_frame.Rotation  = Quaternion.FromToRotation(Vector3.up, rotationAxis);
                m_frame.Rotation *= Quaternion.Euler(0, Vector3.Angle(m_frame.Rotation * Vector3.forward, upVector), 0);
                // This should be rotation axis anchor point.
                m_frame.LocalPosition = Vector3.zero;

                if (name.ToLower().Contains("sprocket"))
                {
                    Model = TrackWheelModel.Sprocket;
                }
                else if (name.ToLower().Contains("idler"))
                {
                    Model = TrackWheelModel.Idler;
                }
                else
                {
                    Model = TrackWheelModel.Roller;
                }
            }
        }