Exemplo n.º 1
0
        /// <summary>
        /// FixedUpdate
        /// When the door is enabled, the FixedUpdate function incrementally interpolates
        /// the position of the door to match the desired end location. The door is then
        /// disabled until it receives another use command.
        /// </summary>
        private void FixedUpdate()
        {
            // Once movement is complete, disable the door until the next trigger.
            if (!bIsMoving)
            {
                this.enabled = false;
            }

            transform.position = Vector3.Lerp(transform.position, finalPos, speed * tLerp);

            Debug.Log("Door Pos: " + transform.position);
            Debug.Log("Final Pos: " + finalPos);

            // Once the door is fully opened/closed, broadcast the associated events.
            if (Mathf.Approximately(transform.position.magnitude, finalPos.magnitude))
            {
                // Reset the lerp variable
                tLerp = 0.1f;

                if (scalar == 1)             // Positive Direction Indicates door was being opened
                {
                    OnFullyOpened.Invoke();
                }
                else if (scalar == -1)
                {
                    OnFullyClosed.Invoke();
                }
            }

            // Keep slightly incrementing the lerp variable
            // to recreate an ease in effect.
            tLerp += 0.1f;
        }
Exemplo n.º 2
0
        /// <summary>
        /// FixedUpdate
        /// When the door is enabled, the FixedUpdate function incrementally interpolates
        /// the position of the door to match the desired end location. The door is then
        /// disabled until it receives another use command.
        /// </summary>
        private void FixedUpdate()
        {
            // Once movement is complete, disable the door until the next trigger.
            if (!bIsMoving)
            {
                this.enabled = false;
            }


            //origin.rotation = Quaternion.Slerp(origin.rotation, Quaternion.Euler(finalPos), 0.5f);
            //transform.rotation.SetLookRotation(origin.position - transform.position);

            origin.rotation = Quaternion.Slerp(origin.rotation, finalPos, tLerp * speed);


            // Once the door is fully opened/closed, broadcast the associated events.
            if (SimilarRotations(origin.rotation, finalPos))
            {
                tLerp = 0.1f;

                // Snap the rotation to the final resting position for proper accuracy.
                origin.rotation = finalPos;

                Debug.Log("Finished Rotating");
                if (scalar == 1)
                {
                    OnFullyOpened.Invoke();
                }
                else if (scalar == -1)
                {
                    OnFullyClosed.Invoke();
                }
            }

            tLerp += Time.deltaTime;
        }