private void Start() { tankArea = GetComponentInParent <TankArea>(); rigidbody = GetComponent <Rigidbody>(); collider = GetComponent <Collider>(); startingPos = transform.position; }
public override void InitializeAgent() { base.InitializeAgent(); m_Shooting = GetComponent <Shooting>(); //m_Movement = GetComponent<Movement>(); m_Movement = GetComponent <LocalMovement>(); Monitor.verticalOffset = 1f; myArea = area.GetComponent <TankArea>(); rayPer = GetComponent <RayPerception>(); myAcademy = myAcademyObj.GetComponent <TankAcademy>(); agentRB = GetComponent <Rigidbody>(); }
//we use fixed update function to avoid things breaking when game is sped up for training private void FixedUpdate() { //Reward for looking at an enemy straight on RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 300) && hit.transform.tag == "tankAgent") { AddReward((1f / agentParameters.maxStep) * 3); Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); } //check if the tank needs to die and "respawn" if (health <= 0) { health = 15; deathCount++; Death.Post(gameObject); transform.position = TankArea.ChooseRandomPosition(startingPos, spawnRadius, spawnRadius); // + new Vector3(0, 0, 7); transform.rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f); } //update varibles tracking ability to shoot timeSinceShoot += Time.fixedDeltaTime; if (timeSinceShoot > 2) { readyShoot = true; } else { readyShoot = false; } }
public override void AgentReset() { //tankArea.ResetArea(); transform.position = TankArea.ChooseRandomPosition(startingPos, spawnRadius, spawnRadius); transform.rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f); }