Exemplo n.º 1
0
    /// <summary>
    /// Manage the rotaiton of the object.
    /// </summary>
    public void Rotate()
    {
        // Dodge bullets incomming
        if (evade.incomming)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, evade.GetEvadeRotation(), Time.deltaTime * rotationSpeed);

            // Constrain rotation ALONG the Z-axis, because the ships are bound to run into each other.
            Quaternion newRotation = transform.rotation;
            newRotation.x      = 0;
            newRotation.y      = 0;
            transform.rotation = newRotation;

            return;
        }

        if (target.GetTarget() != null)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, target.GetAngle(target.GetTarget()), Time.deltaTime * rotationSpeed);

            Quaternion newRotation = transform.rotation;
            newRotation.x      = 0;
            newRotation.y      = 0;
            transform.rotation = newRotation;
            return;
        }
    }