void Update() { float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); if (distanceToPlayer <= attackRadius && !isAttacking) { isAttacking = true; InvokeRepeating("FireProjectile", 0f, secondsBetweenShots); // TODO switch to coroutines } if (distanceToPlayer > attackRadius) { isAttacking = false; CancelInvoke(); } if (distanceToPlayer <= chaseRadius) { aiCharacterControl.SetTarget(player.transform); } else { aiCharacterControl.SetTarget(transform); } }
// Update is called once per frame void Update() { if (player.healthAsPercentage <= Mathf.Epsilon) { //player is already dead StopAllCoroutines(); Destroy(this); //to stop enemy behaviour return; } float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); if ((distanceToPlayer <= attackRadius) && (!isAttacking)) { isAttacking = true; float randomizedDelay = UnityEngine.Random.Range(firingPeriodInSeconds - firingPeriodVariation, firingPeriodInSeconds + firingPeriodVariation); InvokeRepeating("FireProjectile", 0f, randomizedDelay); //TODO switch to Coroutines } if (distanceToPlayer > attackRadius) { CancelInvoke("FireProjectile"); isAttacking = false; } if (distanceToPlayer <= chaseRadius) { //start chasing aICharacterControl.SetTarget(player.transform); } else { aICharacterControl.SetTarget(transform); } }
void OnMouseOverEnemy(Enemy enemy) { if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(1)) { aiCharacterControl.SetTarget(enemy.transform); } }
void Update() { if (player.healthAsPercentage <= Mathf.Epsilon) { StopAllCoroutines(); Destroy(this); // To stop enemy behaviour } float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); if (distanceToPlayer <= attackRadius && !isAttacking) { isAttacking = true; float randomisedDelay = Random.Range(firingPeriodInS - firingPeriodVariation, firingPeriodInS + firingPeriodVariation); InvokeRepeating("FireProjectile", 0f, randomisedDelay); } if (distanceToPlayer > attackRadius) { isAttacking = false; CancelInvoke(); } if (distanceToPlayer <= chaseRadius) { aiCharacterControl.SetTarget(player.transform); } else { aiCharacterControl.SetTarget(transform); } }
void Update() { float distance = Vector3.Distance(player.transform.position, transform.position); if (distance <= attackRadius && !isAttacking) { isAttacking = true; print(gameObject.name + " attackingPlayer"); InvokeRepeating("FireProjectile", 0f, secondsBetweenShots); //TODO make a proper coroutine } if (distance > attackRadius) { CancelInvoke(); isAttacking = false; } else { aICharacterControl.SetTarget(transform); } if (distance < chaseRadius) { //shift alt a comment all aICharacterControl.SetTarget(player.transform); } else { aICharacterControl.SetTarget(transform); } }
void Update() { if (player.healthAsPercentage <= Mathf.Epsilon) { StopAllCoroutines(); Destroy(this); } float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); if (distanceToPlayer <= attackRadius && !isAttacking) { isAttacking = true; InvokeRepeating("FireProjectile", 0f, secondsBetweenShots); } if (distanceToPlayer > attackRadius) { isAttacking = false; CancelInvoke(); } if (distanceToPlayer <= chaseRadius) { aiCharacterControl.SetTarget(player.transform); } else { aiCharacterControl.SetTarget(transform); } }
void OnMouseOverPotentiallyWalkable(Vector3 destination) { if (Input.GetMouseButton(0)) { walkTarget.transform.position = destination; aiCharacterControl.SetTarget(walkTarget.transform); } }
void Update() { distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); currentTime = Time.time; UpdateImmunityGracePeriod(); if (distanceToPlayer <= aggroRange) { MakeMoveAttackDecision(); } else { // do nothing aICharacterControl.SetTarget(transform); } }
void ProcessMouseClick(RaycastHit raycastHit, int layerHit) { switch (layerHit) { case enemyLayerNumber: GameObject enemy = raycastHit.collider.gameObject; aiCharacterControl.SetTarget(enemy.transform); break; case walkableLayerNumber: walkTarget.transform.position = raycastHit.point; aiCharacterControl.SetTarget(walkTarget.transform); break; default: Debug.LogWarning("Don't know how to handle click for player movement"); return; } }
void ProcessMouseClick(RaycastHit raycastHit, int layerHit) { switch (layerHit) { case 8: //walkable walkTarget.transform.position = raycastHit.point; aiCharacterControl.SetTarget(walkTarget.transform); break; case 9: //enemy GameObject enemy = raycastHit.collider.gameObject; aiCharacterControl.SetTarget(enemy.transform); break; default: //everything else Debug.LogWarning("Invalid Movement"); return; } }
void ProcessMouseClick(RaycastHit raycastHit, int layerHit) { switch (layerHit) { case enemyLayerNumber: //navigate to the enemy GameObject enemy = raycastHit.collider.gameObject; aiCharacterControl.SetTarget(enemy.transform); break; case walkableLayerNumber: //navigate to point on the ground walkTarget.transform.position = raycastHit.point; aiCharacterControl.SetTarget(walkTarget.transform); break; default: Debug.Log("Dont know how to handle mouse clikc or player momevement"); break; } }
private void ProcessMouseClick(RaycastHit raycastHit, int layerHit) { switch (layerHit) { case enemyLayerNumber: // navigate to enemy GameObject enemy = raycastHit.collider.gameObject; aiCharacterControl.SetTarget(enemy.transform); break; case walkableLayerNumber: // navigate to point on gorund walkTarget.transform.position = raycastHit.point; aiCharacterControl.SetTarget(walkTarget.transform); break; default: Debug.LogWarning("Cant handle layer in ProcessMouseClick"); break; } }
// try mouse button (1) for pathifnding to enemies while still using ThirdPersonController script void MouseOverEnemy(Enemy enemy) { if (Input.GetMouseButtonDown(1)) { AIControl.SetTarget(enemy.transform); float distance = (transform.position - enemy.transform.position).magnitude; if (distance <= NavMesh.stoppingDistance) { AIControl.ResetTarget(); } } }
void WalkTo(Vector3 destinationPosition) { //Vector3 pos = new Vector3(destinationPosition.x, 0f, destinationPosition.z); walkTarget.transform.position = destinationPosition; aICharacterControl.SetTarget(walkTarget.transform); }