void FixedUpdate() { // Define GameObject list which has columnPoolSize GameObject Agent = GameObject.FindGameObjectWithTag("Bird"); BirdAgent BirdAgentScript = Agent.GetComponent <BirdAgent> (); BirdAgentScript.SendMessage("RewardScore", 0f); }
// If something collide on Trigger private void OnTriggerEnter2D(Collider2D other) { // if collided object is bird if (other.GetComponent <BirdAgent> () != null) { BirdAgent BirdAgentScript = other.GetComponent <BirdAgent> (); BirdAgentScript.SendMessage("RewardScore", 1.0f); GameControl.instance.BirdScored(false); } }
private Vector3 Evade(Transform target_Agent) { BirdAgent target_info = target_Agent.GetComponent <BirdAgent>(); Vector3 target_speed = Vector3.zero; if (target_info != null) { target_speed = target_info._velocity; } Vector3 correctedTargetPos = new Vector3(target_Agent.position.x, transform.position.y, target_Agent.position.z); Vector3 dir = correctedTargetPos - transform.position; float lookAheadTime = 1.0f; if (target_info != null) { lookAheadTime = dir.magnitude / (_maxSpeed + target_info._maxSpeed); } return(Flee(correctedTargetPos + (target_speed * lookAheadTime))); }
// Update is called once per frame void FixedUpdate() { GameObject Agent = GameObject.FindGameObjectWithTag("Bird"); BirdAgent BirdAgentScript = Agent.GetComponent <BirdAgent> (); bool is_dead = BirdAgentScript.isDead; init_game = false; if (is_dead == true) { for (int i = 0; i < columnPoolSize; i++) { columns[i].transform.position = objectPoolPosition; init_game = true; } } timeSinceLasetSpawned += 0.015f; // If more than spawnRate after last spawn, spawn new column if ((GameControl.instance.gameOver == false && timeSinceLasetSpawned >= spawnRate) || (init_game == true)) { timeSinceLasetSpawned = 0; // Make random y position float spawnYPosition = Random.Range(columnMin, columnMax); // Position column columns[currentColumn].transform.position = new Vector2(spawnXPosition, spawnYPosition); // Add column index currentColumn++; // Initialize the column index if (currentColumn >= columnPoolSize) { currentColumn = 0; } } }
private Vector3 Pursuit() { if (target_agent != null) { // 타겟의 현재 속도를 가져옴 BirdAgent target_info = target_agent.GetComponent <BirdAgent>(); Vector3 target_speed = Vector3.zero; if (target_info != null) { target_speed = target_info._velocity; } // 타겟의 y좌표를 보정 Vector3 correctedTargetPos = target_agent.position; correctedTargetPos.y = transform.position.y; // 추격 대상의 방향을 계산, 바로 앞인 경우 대상을 그대로 추적하게 함 Vector3 dir = correctedTargetPos - transform.position; double relativeHeading = Vector3.Dot(_velocity.normalized, target_speed.normalized); if (Vector3.Dot(dir.normalized, _velocity.normalized) > 0 && relativeHeading < -0.95) { return(Seek(correctedTargetPos)); } float lookAheadTime = 1.0f; if (target_info != null) { lookAheadTime = dir.magnitude / (_maxSpeed + target_info._maxSpeed); } return(Seek(correctedTargetPos + (target_speed * lookAheadTime))); } // 추격 대상이 없을 경우 조종힘을 반환하지 않음. return(Vector3.zero); }