Ejemplo n.º 1
0
    public void Collide(SwordTip tip)
    {
        shouldDie = true;

        hitSpeed    = tip.speed;
        hitVelocity = tip.velocity;
    }
    /**
     * tip  - lastTip
     *  |   \     |
     * base - lastBase
     */
    void DetectCollision(SwordTip tip, LiveBlock block)
    {
        Vector3 tipPosition = tip.tipPosition, lastTipPosition = tip.lastTipPosition, basePosition = tip.basePosition, lastBasePosition = tip.lastBasePosition;
//		Debug.DrawLine(tipPosition, lastTipPosition, Color.magenta);
//		Debug.DrawLine(tipPosition, lastBasePosition, Color.magenta);
//		Debug.DrawLine(tipPosition, basePosition, Color.magenta);
//		Debug.DrawLine(lastBasePosition, lastTipPosition, Color.magenta);
//		Debug.DrawLine(lastBasePosition, basePosition, Color.magenta);

        float   t;
        Vector3 blockTopLeft = block.transform.TransformPoint(blockPoint1), blockTipRight = block.transform.TransformPoint(blockPoint2);

        Debug.DrawLine(blockTopLeft, blockTipRight, Color.cyan);

        if (RayQuadIntersection(blockTopLeft, blockTipRight - blockTopLeft, tipPosition, lastTipPosition, lastBasePosition, basePosition, out t) && 0 <= t && t <= 1)
        {
            block.Collide(tip);
        }
    }