Ejemplo n.º 1
0
    void DoThrow(Vector3 pos, float speed, float angle, bool applyBodyVelocity)
    {
        mBody.ResetCollision();

        attachSpriteAnim.Play(attachSpriteClipEmpty);

        bomb.transform.position        = pos;
        bomb.transform.rotation        = throwPoint.rotation;
        bomb.rigidbody.angularVelocity = Vector3.zero;
        bomb.rigidbody.velocity        = Vector3.zero;

        Vector3 newVel;

        if (applyBodyVelocity)
        {
            Vector3 bodyLVel = mBody.localVelocity;

            float velX = mBodySpriteCtrl.isLeft ? bodyLVel.x <0.0f ? bodyLVel.x : 0.0f : bodyLVel.x> 0.0 ? bodyLVel.x : 0.0f;
            float velY = mBody.localVelocity.y < 0 ? 0.0f : mBody.localVelocity.y;

            newVel = bomb.transform.localToWorldMatrix.MultiplyVector(new Vector3(velX, velY));
        }
        else
        {
            newVel = Vector3.zero;
        }

        bomb.SetActive(true);
        mBombCtrl.Activate();

        if (speed != 0.0f)
        {
            Vector3 dir = mBodySpriteCtrl.isLeft ? -mBody.dirHolder.right : mBody.dirHolder.right;

            Quaternion rot = Quaternion.AngleAxis(angle, mBodySpriteCtrl.isLeft ? -Vector3.forward : Vector3.forward);

            dir = rot * dir;

            newVel += dir * speed;
        }

        bomb.rigidbody.AddForce(newVel, ForceMode.VelocityChange);

        StartCoroutine(DoBombCorrection(mBody.gravityController.up));

        tk2dBaseSprite bombSpr = bomb.GetComponentInChildren <tk2dBaseSprite>();

        if (bombSpr)
        {
            bombSpr.FlipX = mBodySpriteCtrl.isLeft;
        }

        mPlayer.HUD.targetOffScreen.gameObject.SetActive(false);

        if (bombGrabber)
        {
            bombGrabber.gameObject.SetActive(true);
        }
    }