Ejemplo n.º 1
0
    /// <summary>
    /// Called when either bat hits this ball.
    /// mainly about the speed calculating
    /// </summary>
    protected virtual void GetBatHit(Collision other)
    {
        PlayerBat hitPlayer = other.gameObject.GetComponent <PlayerBat>();

        if (hitPlayer.GetBatState() == (int)PlayerBat.BatState.none)
        {
            return;
        }

        ContactPoint contactPoint = other.contacts[0];
        //Vector3 curDir = m_Rb.velocity.normalized;
        //Vector3 newDir = Vector3.Reflect(curDir, contactPoint.normal);
        //Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, newDir);
        //transform.rotation = rotation;
        Vector3 newDir = contactPoint.normal;

        m_Rb.velocity = newDir.normalized * m_Rb.velocity.magnitude * 8f;
    }