Exemplo n.º 1
0
        DiscreteStep(int Action_)
        {
            base.DiscreteStep(Action_);

            switch (Action_)
            {
            case Forward:
                for (int i = 0; i < NumBulletPerRelease; i++)
                {
                    GameObject Temp_Bullet_Handeler;
                    Temp_Bullet_Handeler = Instantiate(Bullet, Bullet_Emitter.transform.position,
                                                       Bullet_Emitter.transform.rotation) as GameObject;
                    var vs =
                        Vector3.Normalize(Vector3.Slerp((Bullet_EmitterLeftEdge.transform.position
                                                         - Bullet_Emitter.transform.position),
                                                        (Bullet_EmitterRightEdge.transform.position - Bullet_Emitter.transform.position),
                                                        Random.value));
                    Temp_Bullet_Handeler.GetComponent <Rigidbody>().velocity = vs * 10f;
                    Destroy(Temp_Bullet_Handeler, 3.0f);
                }
                Player.GetComponentInChildren <Rigidbody>().AddForce(Player.transform.TransformVector(
                                                                         Vector3.forward * 40f));
                Player.GetComponentInChildren <Rigidbody>().angularVelocity = Vector3.zero;
                break;

            default:
                break;
            }
        } // Step
Exemplo n.º 2
0
        EmmitBullet(Vector3 direction)
        {
            // emmit Bullet towards direction

            // create Bullet object
            GameObject Temp_Bullet_Handeler;

            Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitter[0].transform.position + direction,
                                               BulletEmitter[0].transform.rotation) as GameObject;

            // Bullet does not collise with Boom or Bullet
            Utils.IgnoreCollision(Temp_Bullet_Handeler, "Boom");
            Utils.IgnoreCollision(Temp_Bullet_Handeler, "Bullet");

            // give Bullet initial speed
            Temp_Bullet_Handeler.GetComponent <Rigidbody>().velocity = transform.TransformDirection(direction * 10.0f);
        }
        DiscreteStep(int Action_)
        {
            if (GetActionSpaceType() != SpaceType.discrete)
            {
                Debug.LogError("ActionSpaceType is not Discrete, DiscreteStep() should not be called.");
            }

            if (AllowGunAttack)
            {
                switch (Action_)
                {
                case Attack:
                    if ((NumBullet > 0) && !Reloading)
                    {
                        GameObject Temp_Bullet_Handeler;
                        Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitter.transform.position,
                                                           BulletEmitter.transform.rotation) as GameObject;
                        Temp_Bullet_Handeler.transform.SetParent(transform, true);
                        Temp_Bullet_Handeler.GetComponent <Rigidbody>().AddForce(
                            BulletEmitter.transform.up * BulletFarwardForce);
                        Destroy(Temp_Bullet_Handeler, 3.0f);
                        NumBullet -= 1.0f;
                        UIPercentageBars["AM"].UpdatePercentage(GetBulletPercentage());
                        if (NumBullet < 1.0f)
                        {
                            Reloading = true;
                        }
                    }
                    break;

                default:
                    break;
                }

                if (Reloading)
                {
                    NumBullet += NumBulletPerLoad;
                    UIPercentageBars["AM"].UpdatePercentage(GetBulletPercentage());
                    if (NumBullet >= FullNumBullet)
                    {
                        Reloading = false;
                    }
                }
            }
        } // DiscreteStep
Exemplo n.º 4
0
        EmmitBullet(Quaternion direction)
        {
            // create Bullet object
            GameObject Temp_Bullet_Handeler;

            Temp_Bullet_Handeler = Instantiate(Fire,
                                               transform.position,
                                               direction) as GameObject;
            Temp_Bullet_Handeler.SetActive(true);

            // Bullet does not collise with Boom or Bullet
            Utils.IgnoreCollision(Temp_Bullet_Handeler, "Boom");
            Utils.IgnoreCollision(Temp_Bullet_Handeler, "Bullet");

            // give the fire initial speed
            Vector3 velocity = Temp_Bullet_Handeler.transform.TransformDirection(Vector3.forward * 10.0f);

            Temp_Bullet_Handeler.GetComponent <Rigidbody>().velocity = velocity;
        }
        DiscreteStep(int Action_)
        {
            if (GetActionSpaceType() != SpaceType.discrete)
            {
                Debug.LogError("ActionSpaceType is not Discrete, DiscreteStep() should not be called.");
            }


            if (AllowGunAttack)
            {
                if (IsShowAimLine)
                {
                    IsHit = Physics.Raycast(RaycastEmitter.transform.position, RaycastEmitter.transform.up,
                                            out AimRaycast);

                    if (IsHit)
                    {
                        AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                                   RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance,
                                                   ((Action_ == Attack) && (NumBullet > 0) &&
                                                    (!Reloading) && (CoolingSteps == 0)) ? AimLineColorWhenAttack : AimLineColor);
                    }
                }
                else
                {
                    AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                               RaycastEmitter.transform.position + RaycastEmitter.transform.up * 0f,
                                               AimLineColor);
                }

                switch (Action_)
                {
                case Attack:
                    if ((NumBullet > 0) && (!Reloading) && (CoolingSteps == 0))
                    {
                        CoolingSteps = NumCoolingSteps + 1;
                        if (ShootType == ShootTypes.Raycast)
                        {
                            if (!IsShowAimLine)
                            {
                                // not showing aim line, so raycast need to be done here
                                IsHit = Physics.Raycast(RaycastEmitter.transform.position,
                                                        RaycastEmitter.transform.up,
                                                        out AimRaycast);
                                if (IsHit)
                                {
                                    AimLine.DrawLineInGameView(RaycastEmitter.transform.position,
                                                               RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance,
                                                               AimLineColorWhenAttack);
                                }
                            }

                            if (IsHit)
                            {
                                if (TrigTags.Contains(AimRaycast.collider.gameObject.tag))
                                {
                                    ArenaNode SubjectNode = Utils.GetBottomLevelArenaNodeInGameObject(
                                        AimRaycast.collider.gameObject);
                                    if (IsKill)
                                    {
                                        SubjectNode.Kill();
                                    }
                                    if (KillHealth != 0f)
                                    {
                                        SubjectNode.IncrementAttribute("Health", -KillHealth);
                                    }
                                }
                                if (AimRaycast.collider.gameObject.tag == "ObstacleDestroyable")
                                {
                                    AimRaycast.collider.gameObject.GetComponent <Destroyable>().Hitted();
                                }
                            }
                        }
                        else if (ShootType == ShootTypes.Bullet)
                        {
                            GameObject Temp_Bullet_Handeler;
                            Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitter.transform.position,
                                                               BulletEmitter.transform.rotation) as GameObject;
                            Temp_Bullet_Handeler.GetComponent <Rigidbody>().AddForce(
                                BulletEmitter.transform.up * BulletFarwardForce);
                        }
                        NumBullet -= 1.0f;

                        foreach (Dictionary <string,
                                             UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars)
                        {
                            UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage());
                        }
                        if (NumBullet < 1.0f)
                        {
                            Reloading = true;
                        }
                    }
                    break;

                default:
                    break;
                }

                if (CoolingSteps > 0)
                {
                    CoolingSteps--;
                }

                if (Reloading)
                {
                    NumBullet += NumBulletPerLoad;
                    foreach (Dictionary <string, UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars)
                    {
                        UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage());
                    }
                    if (NumBullet >= FullNumBullet)
                    {
                        Reloading = false;
                    }
                }
            }
        } // DiscreteStep
Exemplo n.º 6
0
        DiscreteStep(int Action_)
        {
            base.DiscreteStep(Action_);

            Vector3 PalyerVelocity = Player.transform.InverseTransformVector(Player.GetComponent <Rigidbody>().velocity);

            PalyerVelocity = Vector3.zero;

            switch (Action_)
            {
            case Right:
                Player.transform.eulerAngles = new Vector3(
                    Player.transform.eulerAngles.x,
                    transform.eulerAngles.y + 90.0f,
                    Player.transform.eulerAngles.z);
                PalyerVelocity.z = MoveSpeed;
                break;

            case Left:
                Player.transform.eulerAngles = new Vector3(
                    Player.transform.eulerAngles.x,
                    transform.eulerAngles.y - 90.0f,
                    Player.transform.eulerAngles.z);
                PalyerVelocity.z = MoveSpeed;
                break;

            case Forward:
                Player.transform.eulerAngles = new Vector3(
                    Player.transform.eulerAngles.x,
                    transform.eulerAngles.y + 0.0f,
                    Player.transform.eulerAngles.z);
                PalyerVelocity.z = MoveSpeed;
                break;

            case Backward:
                Player.transform.eulerAngles = new Vector3(
                    Player.transform.eulerAngles.x,
                    transform.eulerAngles.y + 180.0f,
                    Player.transform.eulerAngles.z);
                PalyerVelocity.z = MoveSpeed;
                break;

            case Attack:
                if ((NumBullet > 0) && !Reloading)
                {
                    GameObject Temp_Bullet_Handeler;
                    Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitterForward.transform.position,
                                                       BulletEmitterForward.transform.rotation) as GameObject;
                    Temp_Bullet_Handeler.SetActive(true);
                    NumBullet -= 1.0f;
                    UIPercentageBars["AM"].UpdatePercentage(NumBullet / FullNumBullet);
                    if (NumBullet < 1.0f)
                    {
                        Reloading = true;
                    }
                }
                break;

            default:
                break;
            }

            Player.GetComponent <Rigidbody>().velocity = Player.transform.TransformVector(PalyerVelocity);

            if (Reloading)
            {
                NumBullet += NumBulletPerLoad;
                UIPercentageBars["AM"].UpdatePercentage(NumBullet / FullNumBullet);
                if (NumBullet >= FullNumBullet)
                {
                    Reloading = false;
                }
            }
        } // DiscreteStep