//creates a bullet and initiales its parameters
    public void Fire(Transform t, BPAction a, float param, PrevRotWrapper prw)
    {
        //find the correct bulletTag that has info for this bullet
        var bt = bulletTags[a.bulletTagIndex - 1];

        //Debug.Log("bt:"+bt.actions[0].type);

        //get the bullet
        Bullet temp = GetInstance(BulletManager.use.bullets[bt.prefabIndex].bl, t, BulletManager.use.bulletPrefab[bt.prefabIndex]);

        if (prw.prevRotationNull)
        {
            prw.prevRotationNull = false;
            prw.previousRotation = temp.tform.localRotation;
        }
        //set positions equal to its creator, which could be a Firetag or Bullet
        temp.tform.position = t.position;
        temp.tform.rotation = t.rotation;
        //set the abgle offset of new bullet
        float ang;
        if (a.useParam)
            ang = param;
        else
        {
            if (a.randomAngle)
                ang = Random.Range(a.angle.x, a.angle.y);
            else
                ang = a.angle.x;
            if (a.rankAngle)
                ang += BulletManager.use.rank * a.angle.z;
        }

        //actually point the bullet in the right direction
        switch ((DirectionType)a.direction)
        {
            case (DirectionType.TargetPlayer):
                var originalRot = t.rotation;
                var dotHeading = Vector3.Dot(temp.tform.up, BulletManager.use.player.position - temp.tform.position);

                int dir;
                if (dotHeading > 0)
                    dir = -1;
                else
                    dir = 1;
                var angleDif = Vector3.Angle(temp.tform.forward, BulletManager.use.player.position - temp.tform.position);
                temp.tform.rotation = originalRot * Quaternion.AngleAxis((dir * angleDif) - ang, Vector3.right);
                break;

            case (DirectionType.Absolute):
                temp.tform.localRotation = Quaternion.Euler(-(ang - 270), 270, 0);
                break;

            case (DirectionType.Relative):
                temp.tform.localRotation = t.localRotation * Quaternion.AngleAxis(-ang, Vector3.right);
                break;

            case (DirectionType.Sequence):
                temp.tform.localRotation = prw.previousRotation * Quaternion.AngleAxis(-ang, Vector3.right);
                break;
        }
        //record this rotation for next Sequence Direction
        prw.previousRotation = temp.tform.localRotation;
        //set the speed, either from creator's speed data
        if (a.overwriteBulletSpeed)
        {
            float spd;
            if (a.randomSpeed)
                spd = Random.Range(a.speed.x, a.speed.y);
            else
                spd = a.speed.x;
            if (a.rankSpeed)
                spd += BulletManager.use.rank * a.speed.z;

            if (a.useSequenceSpeed)
            {
                sequenceSpeed += spd;
                temp.speed = sequenceSpeed;
            } else
            {
                sequenceSpeed = 0f;
                temp.speed = spd;
            }
        }
        //or bulletTag data
        else
        {
            if (bt.randomSpeed)
                temp.speed = Random.Range(bt.speed.x, bt.speed.y);
            else
                temp.speed = bt.speed.x;
            if (bt.rankSpeed)
                temp.speed += BulletManager.use.rank * bt.speed.z;
        }

        //set the bullets actions array, so it can perform actions later if it has any
        temp.actions = bt.actions;

        //pass random params to bullet, commented out because it seemed to be causing errors and I never used it anyway

        if (a.passParam)
            temp.param = Random.Range(a.paramRange.x, a.paramRange.y);

        //pass param that the creator received form another FireTag before creating this bullet(see readMe file)
        if (a.passPassedParam)
            temp.param = param;
        //give the bullet a reference to this script
        temp.master = this;
        //and activate it
        temp.Activate();
    }
Beispiel #2
0
    //creates a bullet and initiales its parameters
    public void Fire(Transform t, BPAction a, float param, PrevRotWrapper prw)
    {
        //find the correct bulletTag that has info for this bullet
        var bt = bulletTags[a.bulletTagIndex - 1];

        //Debug.Log("bt:"+bt.actions[0].type);

        //get the bullet
        Bullet temp = GetInstance(BulletManager.instance.bullets[bt.prefabIndex].bl, t, BulletManager.instance.bulletPrefab[bt.prefabIndex]);

        if (prw.prevRotationNull)
        {
            prw.prevRotationNull = false;
            prw.previousRotation = temp.transform.localRotation;
        }

        //set positions equal to its creator, which could be a Firetag or Bullet
        temp.transform.position = t.position;
        temp.transform.rotation = t.rotation;
        //set the abgle offset of new bullet
        float ang;

        if (a.useParam)
        {
            ang = param;
        }
        else
        {
            if (a.randomAngle)
            {
                ang = Random.Range(a.angle.x, a.angle.y);
            }
            else
            {
                ang = a.angle.x;
            }
            if (a.rankAngle)
            {
                ang += BulletManager.instance.rank * a.angle.z;
            }
        }

        //actually point the bullet in the right direction
        switch ((DirectionType)a.direction)
        {
        case (DirectionType.TargetPlayer):
            var originalRot = t.rotation;
            var dotHeading  = Vector3.Dot(temp.transform.up, BulletManager.instance.player.position - temp.transform.position);

            int dir;
            if (dotHeading > 0)
            {
                dir = -1;
            }
            else
            {
                dir = 1;
            }
            var angleDif = Vector3.Angle(temp.transform.forward, BulletManager.instance.player.position - temp.transform.position);
            temp.transform.rotation = originalRot * Quaternion.AngleAxis((dir * angleDif) - ang, Vector3.right);
            break;

        case (DirectionType.Absolute):
            temp.transform.localRotation = Quaternion.Euler(-(ang - 270), 270, 0);
            break;

        case (DirectionType.Relative):
            temp.transform.localRotation = t.localRotation * Quaternion.AngleAxis(-ang, Vector3.right);
            break;

        case (DirectionType.Sequence):
            temp.transform.localRotation = prw.previousRotation * Quaternion.AngleAxis(-ang, Vector3.right);
            break;
        }
        //record this rotation for next Sequence Direction
        prw.previousRotation = temp.transform.localRotation;
        //set the speed, either from creator's speed data
        if (a.overwriteBulletSpeed)
        {
            float spd;
            if (a.randomSpeed)
            {
                spd = Random.Range(a.speed.x, a.speed.y);
            }
            else
            {
                spd = a.speed.x;
            }
            if (a.rankSpeed)
            {
                spd += BulletManager.instance.rank * a.speed.z;
            }

            if (a.useSequenceSpeed)
            {
                sequenceSpeed += spd;
                temp.speed     = sequenceSpeed;
            }
            else
            {
                sequenceSpeed = 0f;
                temp.speed    = spd;
            }
        }
        //or bulletTag data
        else
        {
            if (bt.randomSpeed)
            {
                temp.speed = Random.Range(bt.speed.x, bt.speed.y);
            }
            else
            {
                temp.speed = bt.speed.x;
            }
            if (bt.rankSpeed)
            {
                temp.speed += BulletManager.instance.rank * bt.speed.z;
            }
        }

        //set the bullets actions array, so it can perform actions later if it has any
        temp.actions = bt.actions;

        //pass random params to bullet, commented out because it seemed to be causing errors and I never used it anyway

        if (a.passParam)
        {
            temp.param = Random.Range(a.paramRange.x, a.paramRange.y);
        }

        //pass param that the creator received form another FireTag before creating this bullet(see readMe file)
        if (a.passPassedParam)
        {
            temp.param = param;
        }
        //give the bullet a reference to this script
        temp.master = this;
        //and activate it
        temp.Activate();
    }