void PerformNextRequest() { //Debug.Log("Queue Count: " + requestQueue.Count); if (isProcessing) { return; } if (requestQueue.Count == 0) { return; } isProcessing = true; currentRequest = requestQueue.Dequeue(); StartCoroutine ( FindPath ( currentRequest.transform.position, (currentRequest.TargetDestination == null) ? currentRequest.lastTargetPosition : currentRequest.TargetDestination.position ) ); //Debug.Log(Time.deltaTime); //Debug.Log("Queue Count: " + requestQueue.Count); }
void GetNextTarget(string side) { canSwitchTarget = false; StartCoroutine(SnapifyChangeTarget()); Collider[] colliders = Physics.OverlapSphere(transform.position, lockonDist, 1 << 11); if (colliders.Length == 1) { return; } InputParent currentEnemyTarget = states.enemyTarget; float smallestAngle = 180; for (int i = 0; i < colliders.Length; i++) { NPCInput enemy = colliders[i].GetComponent <NPCInput>(); if (enemy != null) { if (Physics.Linecast(states.aem.head.position, enemy.states.aem.body.position, 1 << 0)) { continue; } if (enemy == currentEnemyTarget) { continue; } Vector3 to = colliders[i].transform.position - mainCam.transform.position; float angle = Vector3.SignedAngle(mainCam.transform.forward, to, mainCam.transform.up); if (side == "left" && angle > 0) { continue; } if (side == "right" && angle < 0) { continue; } if (Mathf.Abs(angle) < smallestAngle) { states.LockonOn(enemy); smallestAngle = Mathf.Abs(angle); } } } if (states.enemyTarget == null) { states.LockOff(); } }
public void Activate(int level, int offset) { GameObject enemy = ObjectPool.Instance.GetObject(enemyPrefab, spawnPoint.position + offset * Vector3.forward, spawnPoint.rotation); NPCInput eI = enemy.GetComponent<NPCInput>(); eI.states.Revive(level); if (enemyPrefab == "Boss(Clone)") { GameMasterScript.theBoss = enemy.GetComponent<EnemyInput>(); } }
void InputLookPosition() { float distance = 150; if (states.aim || states.isInAction || states.animator.GetBool("stillAiming")) //if (states.animator.GetBool("aim") || states.isInAction) { Ray ray = new Ray(mainCam.transform.position, mainCam.transform.forward); RaycastHit hitInfo; if (Physics.Raycast( ray, out hitInfo, distance, 1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 11)) { states.lookPosition = hitInfo.point; NPCInput npc = hitInfo.collider.GetComponent <NPCInput>(); if (npc == null) { return; } if (npc.ui.activeSelf) { return; } npc.StartCoroutine(npc.ShowUI()); } else { states.lookPosition = mainCam.transform.position + mainCam.transform.forward * distance; } } else { states.lookPosition = mainCam.transform.position + mainCam.transform.forward * distance; } /*if (states.lockon && states.enemyTarget != null) * { * states.lookPosition = states.enemyTarget.lockonPosition; * }*/ }
void GetEnemyTarget() { Collider[] colliders = Physics.OverlapSphere(transform.position, lockonDist, 1 << 11); if (colliders.Length == 0) { states.LockOff(); return; } for (int i = 0; i < colliders.Length; i++) { NPCInput enemy = colliders[i].GetComponent <NPCInput>(); if (enemy != null) { if (Physics.Linecast(states.aem.head.position, enemy.states.aem.body.position, 1 << 0)) { continue; } if (states.enemyTarget == null) { states.LockonOn(enemy); return; } else { Vector3 to = colliders[i].transform.position - mainCam.transform.position; float newAngle = Vector3.SignedAngle(mainCam.transform.forward, to, mainCam.transform.up); to = states.enemyTarget.transform.position - mainCam.transform.position; float oldAngle = Vector3.SignedAngle(mainCam.transform.forward, to, mainCam.transform.up); if (Mathf.Abs(newAngle) < Mathf.Abs(oldAngle)) { states.LockonOn(enemy); } } } } if (states.enemyTarget == null) { states.LockOff(); } }
public void RequestPath(NPCInput npc) { requestQueue.Enqueue(npc); npc.pathRequestOrderPlaced = true; PerformNextRequest(); }