コード例 #1
0
 private void Engine_PlayerHitEvent(Player player, TankShell shell)
 {
     if (player.CurrShields > 0)
     {
         player.CurrShields = (byte)Math.Max(0, player.CurrShields - TankShell.shellDmg);
     }
     else
     {
         player.CurrHealth -= TankShell.shellDmg;
         if (player.CurrHealth <= 0)
         {
             newDeathIDs.Enqueue(new Tuple <int, int>(shell.OwnerPID, player.ID));
         }
     }
 }
コード例 #2
0
    /// <summary>
    /// Spawns a tank shell and sets the association with this player
    /// </summary>
    public void Attack(float force, Vector3 turretRotation)
    {
        if (this.isDisabled)
        {
            return;
        }

        // Syncs up the rotations
        this.turretLookAt = turretRotation;

        GameObject shellGO   = Instantiate(this.shellPrefab, this.shellSpawnPoint.transform.position, this.shellSpawnPoint.transform.rotation);
        TankShell  tankShell = shellGO.GetComponent <TankShell>();

        tankShell.PlayerId  = this.playerId;
        tankShell.FireForce = force;
    }
コード例 #3
0
 public static void FireShell(Rigidbody m_ShellPrefab, Vector3 position, Quaternion rotation, Vector3 velocity, int tankId)
 {
     if (s_DisabledShellList.Count > 0)
     {
         TankShell s = s_DisabledShellList.Pop();
         s.transform.position = position;
         s.transform.rotation = rotation;
         s.GetComponent <Rigidbody>().velocity = velocity;
         s.gameObject.SetActive(true);
         s.m_TankIdOwner = tankId;
     }
     else
     {
         Rigidbody shellInstance = Instantiate(m_ShellPrefab, position, rotation) as Rigidbody;
         shellInstance.velocity = velocity;
         shellInstance.GetComponent <TankShell>().m_TankIdOwner = tankId;
     }
 }
コード例 #4
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        if (IsDead())
        {
            return;
        }

        float forwardMovement = vectorAction[0];
        float turnValue       = vectorAction[1];
        bool  tryingToShoot   = vectorAction[2] > 0.5f;

        if (forwardMovement < 0)
        {
            turnValue *= -1;
        }
        forwardMovement = Mathf.Clamp(forwardMovement, -1, 1);
        turnValue       = Mathf.Clamp(turnValue, -1, 1);

        rBody.AddForce(transform.forward * forwardMovement * m_Speed, ForceMode.VelocityChange);
        float      turn         = turnValue * m_TurnSpeed * Time.deltaTime;
        Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);

        rBody.MoveRotation(rBody.rotation * turnRotation);

        if (tryingToShoot && Time.time > m_TimeOfLastShot + m_TimeBetweenShots)
        {
            m_TimeOfLastShot = Time.time;
            TankShell.FireShell(m_Shell,
                                m_FireTransform.position,
                                m_FireTransform.rotation,
                                m_ShellSpeed * m_FireTransform.forward,
                                m_TankId);
        }

        AddReward(-1f / agentParameters.maxStep);

        if (Math.Abs(transform.position.x) > 35 ||
            Math.Abs(transform.position.z) > 35)
        {
            SetReward(-1);
            Done();
        }
    }
コード例 #5
0
    //Fire Gun
    public void Fire()
    {
        AudioSource.PlayClipAtPoint(gunFireSound, this.transform.position, PlayerPrefs.GetFloat("FXVol"));
        //Set isLoaded to false
        isLoaded = false;
        //create gameObject Shell
        GameObject shell = Instantiate(data.shellPrefab, gunPosition.position, Quaternion.identity) as GameObject;

        shell.transform.name = "Shell";

        TankShell shellScript = shell.GetComponent <TankShell>();

        shellScript.SetTankData(data);

        //Add Rigidbody component to shell
        Rigidbody shellRb = shell.GetComponent <Rigidbody> ();

        shellRb.AddForce(motor.tf.forward * data.shellForce);

        //Simulate Reload Speed
        StartCoroutine(WaitAndReload(data.reloadTime));
    }
コード例 #6
0
    public override void Action(int dirx, int diry)
    {
        TankShellSoundManagerScript.soundInstance.PlaySound();
        Vector3   position = parent.transform.position;
        TankShell shell    = Instantiate(attack, position, Quaternion.identity).GetComponent <TankShell>();

        shell.parent             = parent;
        shell.transform.position = new Vector2(position.x + dirx, position.y + diry);
        shell.direction          = new Vector2(dirx, diry);

        if (diry < 0)
        {
            shell.transform.rotation = Quaternion.AngleAxis(-90f, Vector3.forward);
        }
        else if (diry > 0)
        {
            shell.transform.rotation = Quaternion.AngleAxis(90f, Vector3.forward);
        }
        else if (dirx < 0)
        {
            shell.transform.rotation = Quaternion.AngleAxis(180f, Vector3.forward);
        }
    }
コード例 #7
0
    //public float elev;

    void Awake()
    {
        tankShell = shellSettings.GetComponent <TankShell>();
    }
コード例 #8
0
ファイル: TankAcademy.cs プロジェクト: zeroblitz36/ml-agents
    public override void AcademyReset()
    {
        if (m_NumberOfAgents > m_SpawnPoints.Length)
        {
            Debug.LogError("There are not enough spawn points for all the agents");
        }
        if (m_NumberOfAgents <= 0)
        {
            Debug.LogError("The number of agents must be a positive number");
        }

        for (int i = 0; i < m_Agents.Length; i++)
        {
            if (m_Agents[i] != null)
            {
                TankAgentScript currentTankAgent = m_Agents[i].GetComponent <TankAgentScript>();
                currentTankAgent.Done();
                Destroy(m_Agents[i]);
            }
        }

        if (m_isPlayerPresent)
        {
            m_Agents[0] = CreateTankAgent(m_TankAgentPrefab, m_PlayerBrain, m_SpawnPoints[0].position, Quaternion.identity);
        }
        else
        {
            m_Agents[0] = CreateTankAgent(m_TankAgentPrefab, m_LearningBrain, m_SpawnPoints[0].position, Quaternion.identity);
        }

        for (int i = 1; i < m_NumberOfAgents; i++)
        {
            m_Agents[i] = CreateTankAgent(m_TankAgentPrefab, m_LearningBrain, m_SpawnPoints[i].position, Quaternion.identity);
        }

        for (int i = 0; i < m_NumberOfAgents; i++)
        {
            m_CameraControl.m_Targets[i] = m_Agents[i].transform;
            TankAgentScript currentTankAgent = m_Agents[i].GetComponent <TankAgentScript>();
            currentTankAgent.m_TankId        = i;
            currentTankAgent.cam             = m_mainCamera;
            currentTankAgent.tankAcademy     = this;
            currentTankAgent.enemyTankAgents = new TankAgentScript[m_NumberOfAgents - 1];

            int k = 0;
            for (int j = 0; j < m_NumberOfAgents; j++)
            {
                if (i == j)
                {
                    continue;
                }
                TankAgentScript otherTankAgent = m_Agents[j].GetComponent <TankAgentScript>();
                currentTankAgent.enemyTankAgents[k] = otherTankAgent;
                ++k;
            }
        }

        m_CameraControl.m_Targets[m_NumberOfAgents] = m_goalSphere.transform;

        TankShell.DisableAllShells();

        ResetGoalSphere();
    }