public void Update() { if (tempDisable == false) { if (TopDownUIManager.instance != null) { if (Input.GetKey(tdcc_InputManager.interactKey)) { MoveCharacter(); } else { if (followingCursor == true) { if (focusedTarget == null) { //Vector3 pos = new Vector3(hitPoint.x, hitPoint.y, hitPoint.z); GameObject tmpPoint = Instantiate(noFocusWalkPoint, hitPoint, Quaternion.identity) as GameObject; SetFocus(tmpPoint.transform); hasWalkPoint = true; } followingCursor = false; } } } else { if (Input.GetKey(defInteractKey)) { MoveCharacter(); } else { if (followingCursor == true) { if (focusedTarget == null) { //Vector3 pos = new Vector3(hitPoint.x, hitPoint.y, hitPoint.z); GameObject tmpPoint = Instantiate(noFocusWalkPoint, hitPoint, Quaternion.identity) as GameObject; SetFocus(tmpPoint.transform); hasWalkPoint = true; } followingCursor = false; } } } if (followingCursor == false) { if (focusedTarget != null) { distanceToFocus = Vector3.Distance(transform.position, focusedTarget.position); tdcc_NavMeshAgent.SetDestination(focusedTarget.position); if (tdcc_NavMeshAgent.remainingDistance > tdcc_NavMeshAgent.stoppingDistance) { tdcc_Main.TDCC_MoveCharacter(tdcc_NavMeshAgent.desiredVelocity); if (tdcc_Main.vegetationMoveWindZone != null) { tdcc_Main.vegetationMoveWindZone.gameObject.SetActive(true); } } else { tdcc_Main.TDCC_MoveCharacter(Vector3.zero); if (tdcc_Main.vegetationMoveWindZone != null) { tdcc_Main.vegetationMoveWindZone.gameObject.SetActive(false); } //We needed to put this as sometimes our agent wont rotate all the way toward target Quaternion targetRotation = Quaternion.LookRotation(focusedTarget.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * faceEnemyRotSpeed); //COMBAT if (focusedTarget.tag == enemyTag && distanceToFocus < tdcc_Main.tdcm_NavMeshAgent.stoppingDistance) { if (focusedTarget.GetComponent <TopDownCharacterCard>() && focusedTarget.GetComponent <TopDownCharacterCard>().IsDead() == false) { if (tdr_Spellcaster != null) { if (tdr_Spellcaster.castingSpell == false) { //here we only attack with melee int i = (int)tdcc_EquipmentManager.weaponTypeUsed; int h = (int)tdcc_EquipmentManager.weaponHoldingType; tdcc_Main.tdcm_animator.SetBool("TargetInFront", true); tdcc_Main.tdcm_animator.SetFloat("WeaponType", (float)i); tdcc_Main.tdcm_animator.SetFloat("WeaponHoldingType", (float)h); tdcc_Main.tdcm_animator.SetBool("Attacking", true); } } else { //here we only attack with melee int i = (int)tdcc_EquipmentManager.weaponTypeUsed; int h = (int)tdcc_EquipmentManager.weaponHoldingType; tdcc_Main.tdcm_animator.SetBool("TargetInFront", true); tdcc_Main.tdcm_animator.SetFloat("WeaponType", (float)i); tdcc_Main.tdcm_animator.SetFloat("WeaponHoldingType", (float)h); tdcc_Main.tdcm_animator.SetBool("Attacking", true); } } else { RemoveFocus(); } } else { tdcc_Main.tdcm_animator.SetBool("TargetInFront", false); } } } else { RemoveFocus(); } } } else { RemoveFocus(); } }
public void Update() { if (activePlayerAi == true) { if (main.tdcm_NavMeshAgent != null) { if (activeFocus != characterManager.controllingCharacter) { activeFocus = characterManager.controllingCharacter.transform; } if (activeFocus != null) { distanceToActive = Vector3.Distance(transform.position, activeFocus.position); if (activeFocus.GetComponent <Animator>().GetBool("Attacking") == false) { if (distanceToActive > 3f) { main.tdcm_NavMeshAgent.SetDestination(activeFocus.position); main.TDCC_MoveCharacter(main.tdcm_NavMeshAgent.desiredVelocity); } else { main.tdcm_NavMeshAgent.SetDestination(transform.position); main.TDCC_MoveCharacter(Vector3.zero); } enemyFocus = null; main.tdcm_animator.SetBool("TargetInFront", false); main.tdcm_animator.SetBool("Attacking", false); } else { if (activeFocus.GetComponent <TopDownControllerInteract>().focusedTarget != null) { if (enemyFocus == null) { enemyFocus = activeFocus.GetComponent <TopDownControllerInteract>().focusedTarget; } //float distanceToActivesFocus = Vector3.Distance(transform.position, enemyFocus.position); if (main.tdcm_NavMeshAgent.remainingDistance > interact.enemyStopDistance) { main.TDCC_MoveCharacter(main.tdcm_NavMeshAgent.desiredVelocity); if (main.vegetationMoveWindZone != null) { main.vegetationMoveWindZone.gameObject.SetActive(true); } main.tdcm_NavMeshAgent.SetDestination(enemyFocus.position); main.tdcm_animator.SetBool("TargetInFront", false); } else { main.TDCC_MoveCharacter(Vector3.zero); main.tdcm_NavMeshAgent.SetDestination(transform.position); if (main.vegetationMoveWindZone != null) { main.vegetationMoveWindZone.gameObject.SetActive(false); } //We needed to put this as sometimes our agent wont rotate all the way toward target Quaternion targetRotation = Quaternion.LookRotation(enemyFocus.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * interact.faceEnemyRotSpeed); //COMBAT if (enemyFocus.GetComponent <TopDownCharacterCard>() && enemyFocus.GetComponent <TopDownCharacterCard>().IsDead() == false) { //here we only attack with melee int i = (int)equipmentManager.weaponTypeUsed; int h = (int)equipmentManager.weaponHoldingType; main.tdcm_animator.SetBool("TargetInFront", true); main.tdcm_animator.SetFloat("WeaponType", (float)i); main.tdcm_animator.SetFloat("WeaponHoldingType", (float)h); main.tdcm_animator.SetBool("Attacking", true); } else { main.tdcm_animator.SetBool("TargetInFront", false); main.tdcm_animator.SetBool("Attacking", false); } } } else { enemyFocus = null; } } } } } if (health < 0f) { maxHealth = 0f; Die(); } if (health > maxHealth) { health = maxHealth; } if (TopDownUIManager.instance != null) { if (placeBarOverHead != npcBar.placeBarOverHead) { placeBarOverHead = npcBar.placeBarOverHead; } if (mouseOver == true) { if (placeBarOverHead == false) { Vector2 tmp = mainCamera.WorldToScreenPoint(transform.position); Vector2 namePos = new Vector3(tmp.x, tmp.y + (npcBar.yOffset * npcBar.screenY)); npcBar.transform.position = namePos; } else { if (nameBarPosition != null) { Vector2 tmp = mainCamera.WorldToScreenPoint(nameBarPosition.position); Vector2 namePos = new Vector3(tmp.x, tmp.y + (npcBar.yOffsetOverHead * npcBar.screenY)); npcBar.transform.position = namePos; } } } } //NewUpdate(); }
public void Update() { if (tdc_Main != null) { if (tdc_Main.tdcm_animator != null) { velocity = tdc_Main.tdcm_animator.GetFloat("Forward"); } if (focus != null) { tdc_Main.tdcm_NavMeshAgent.SetDestination(focus.position); if (tdc_Main.tdcm_NavMeshAgent.remainingDistance > tdc_Main.tdcm_NavMeshAgent.stoppingDistance) { tdc_Main.TDCC_MoveCharacter(tdc_Main.tdcm_NavMeshAgent.velocity); } else { tdc_Main.TDCC_MoveCharacter(Vector3.zero); if (tdc_Main.tdcm_NavMeshAgent.remainingDistance != 0f) { if (td_EquipmentManager != null) { int i = (int)td_EquipmentManager.weaponTypeUsed; tdc_Main.tdcm_animator.SetFloat("WeaponType", (float)i); } else { tdc_Main.tdcm_animator.SetFloat("WeaponType", 1); } //Add rotation Quaternion targetRotation = Quaternion.LookRotation(focus.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 500f); tdc_Main.tdcm_animator.SetBool("TargetInFront", true); tdc_Main.tdcm_animator.SetBool("Attacking", true); } else { tdc_Main.tdcm_animator.SetBool("TargetInFront", false); } } } else { if (tdc_Main.tdcm_NavMeshAgent != null) { tdc_Main.tdcm_NavMeshAgent.SetDestination(startPos); if (tdc_Main.tdcm_NavMeshAgent.remainingDistance > tdc_Main.tdcm_NavMeshAgent.stoppingDistance) { tdc_Main.TDCC_MoveCharacter(tdc_Main.tdcm_NavMeshAgent.velocity); } else { tdc_Main.TDCC_MoveCharacter(Vector3.zero); } } if (tdc_Main.tdcm_animator != null) { tdc_Main.tdcm_animator.SetBool("Attacking", false); tdc_Main.tdcm_animator.SetBool("TargetInFront", false); } } distToStartPos = Vector3.Distance(transform.position, startPos); } }