private void OnTriggerEnter(Collider collision) { if (collision.tag == "Player") { PlayerStats playerStats = collision.GetComponent <PlayerStats>(); CharacterManager enemyCharacterManager = collision.GetComponent <CharacterManager>(); BlockingCollider shield = collision.transform.GetComponentInChildren <BlockingCollider>(); if (enemyCharacterManager != null) { if (enemyCharacterManager.isParrying) { // play animation characterManager.GetComponentInChildren <AnimatorManager>().PlayTargetAnimation("Parried", true); return; } else if (shield != null && enemyCharacterManager.isBlocking) { float physicalDamageAfterBlock = currentWeaponDamage - (currentWeaponDamage * shield.blockingPhysicalDamageAbsorption) / 100; if (playerStats != null) { playerStats.TakeDamage(Mathf.RoundToInt(physicalDamageAfterBlock), "Block Guard"); return; } } } if (playerStats != null) { playerStats.TakeDamage(currentWeaponDamage); } } if (collision.tag == "Enemy") { EnemyStats enemyStats = collision.GetComponent <EnemyStats>(); CharacterManager enemyCharacterManager = collision.GetComponent <CharacterManager>(); BlockingCollider shield = collision.transform.GetComponentInChildren <BlockingCollider>(); if (enemyCharacterManager != null) { if (enemyCharacterManager.isParrying) { // play animation characterManager.GetComponentInChildren <EnemyAnimatorManager>().PlayTargetAnimation("Parried", true); return; } else if (shield != null && enemyCharacterManager.isBlocking) { float physicalDamageAfterBlock = currentWeaponDamage - (currentWeaponDamage * shield.blockingPhysicalDamageAbsorption) / 100; if (enemyStats != null) { enemyStats.TakeDamage(Mathf.RoundToInt(physicalDamageAfterBlock), "Block Guard"); return; } } } if (enemyStats != null) { enemyStats.TakeDamage(currentWeaponDamage); } } if (collision.tag == "Hidden Wall") { HiddenWall hiddenWall = collision.GetComponent <HiddenWall>(); hiddenWall.wallHasBeenHit = true; } }
private void Awake() { characterCastingSpell = GetComponentInParent <CharacterManager>(); }
public void HandleLockOn() { float shortestDistance = Mathf.Infinity; float shortestDistanceOfLeftTarget = Mathf.Infinity; float shortestDistanceOfRightTarget = Mathf.Infinity; Collider[] colliders = Physics.OverlapSphere(targetTransform.position, 26); for (int i = 0; i < colliders.Length; i++) { CharacterManager character = colliders[i].GetComponent <CharacterManager>(); if (character != null) { Vector3 lockTargetDirection = character.transform.position - targetTransform.position; float distanceFromTarget = Vector3.Distance(targetTransform.position, character.transform.position); float viewableAngle = Vector3.Angle(lockTargetDirection, cameraTransform.forward); RaycastHit hit; if (character.transform.root != targetTransform.transform.root && viewableAngle > -50 && viewableAngle < 50 && distanceFromTarget <= maximumLockOnDistance) { if (Physics.Linecast(playerManager.lockOnTransform.position, character.lockOnTransform.position, out hit)) { Debug.DrawLine(playerManager.lockOnTransform.position, character.lockOnTransform.position); if (hit.transform.gameObject.layer == environmentLayer) { //cannot lock on because obstacle } else { //availableTargets.Add(character); if (!character.GetComponent <EnemyStats>().isDead) { availableTargets.Add(character); } else { availableTargets.Remove(character); } } } } } } for (int k = 0; k < availableTargets.Count; k++) { float distanceFromTarget = Vector3.Distance(targetTransform.position, availableTargets[k].transform.position); if (distanceFromTarget < shortestDistance) { shortestDistance = distanceFromTarget; nearestLockOnTarget = availableTargets[k]; } if (inputHandler.lockOnFlag) { //Vector3 relativeEnemyPosition = currentLockOnTarget.transform.InverseTransformPoint(availableTargets[k].transform.position); //var distanceFromLeftTarget = currentLockOnTarget.transform.position.x - availableTargets[k].transform.position.x; //var distanceFromRightTarget = currentLockOnTarget.transform.position.x + availableTargets[k].transform.position.x; Vector3 relativeEnemyPosition = inputHandler.transform.InverseTransformPoint(availableTargets[k].transform.position); var distanceFromLeftTarget = relativeEnemyPosition.x; var distanceFromRightTarget = relativeEnemyPosition.x; // calculation distant from character transform instead of first method if (relativeEnemyPosition.x <= 0.00 && distanceFromLeftTarget > shortestDistanceOfLeftTarget && availableTargets[k] != currentLockOnTarget) { shortestDistanceOfLeftTarget = distanceFromLeftTarget; leftLockTarget = availableTargets[k]; } else if (relativeEnemyPosition.x >= 0.00 && distanceFromRightTarget < shortestDistanceOfRightTarget && availableTargets[k] != currentLockOnTarget) { shortestDistanceOfRightTarget = distanceFromRightTarget; rightLockTarget = availableTargets[k]; } } } }
public void ClearLockOnTargets() { availableTargets.Clear(); nearestLockOnTarget = null; currentLockOnTarget = null; }
public void AttemptBackStabOrRiposte() { //Stamina dependency if (playerStats.CurrentStamina <= 0) { return; } RaycastHit hit; // start point - going out to transforms direction forward - out hit variable - distance 0.5f - scan on layer if (Physics.Raycast(inputHandler.criticalAttackRayCastStartPoint.position, transform.TransformDirection(Vector3.forward), out hit, 0.5f, backStabLayer)) { #region Backstab CharacterManager enemyCharacterManager = hit.transform.gameObject.GetComponentInParent <CharacterManager>(); DamageCollider rightWeapon = weaponSlotManager.rightHandDamageCollider; if (enemyCharacterManager != null) { //check id ( so you cant stab ally ) //pull is into a transform behind the enemy so backstab looks clean playerManager.transform.position = enemyCharacterManager.backStabCollider.deathblowsPosition.position; //rotate us towards that transform Vector3 rotationDirection = playerManager.transform.root.eulerAngles; rotationDirection = hit.transform.position - playerManager.transform.position; rotationDirection.y = 0; rotationDirection.Normalize(); Quaternion tr = Quaternion.LookRotation(rotationDirection); Quaternion targetRotation = Quaternion.Slerp(playerManager.transform.rotation, tr, 500 * Time.deltaTime); playerManager.transform.rotation = targetRotation; int criticalDamage = playerInventory.rightWeapon.criticalDamageMultiplier * rightWeapon.currentWeaponDamage; enemyCharacterManager.pendingCriticalDamage = criticalDamage; //play animation animatorHandler.PlayTargetAnimation("Back Stab", true); //make enemy play animation enemyCharacterManager.GetComponentInChildren <AnimatorManager>().PlayTargetAnimation("Back Stabbed", true); //do damage } #endregion } else if (Physics.Raycast(inputHandler.criticalAttackRayCastStartPoint.position, transform.TransformDirection(Vector3.forward), out hit, 0.7f, riposteLayer)) { #region Riposte CharacterManager enemyCharacterManager = hit.transform.gameObject.GetComponentInParent <CharacterManager>(); DamageCollider rightWeapon = weaponSlotManager.rightHandDamageCollider; if (enemyCharacterManager != null && enemyCharacterManager.canBeRiposted) { playerManager.transform.position = enemyCharacterManager.riposteCollider.deathblowsPosition.position; Vector3 rotationDirection = playerManager.transform.root.eulerAngles; rotationDirection = hit.transform.position - playerManager.transform.position; rotationDirection.y = 0; rotationDirection.Normalize(); Quaternion tr = Quaternion.LookRotation(rotationDirection); Quaternion targetRotation = Quaternion.Slerp(playerManager.transform.rotation, tr, 500 * Time.deltaTime); playerManager.transform.rotation = targetRotation; int criticalDamage = playerInventory.rightWeapon.criticalDamageMultiplier * rightWeapon.currentWeaponDamage; enemyCharacterManager.pendingCriticalDamage = criticalDamage; animatorHandler.PlayTargetAnimation("Riposte", true); enemyCharacterManager.GetComponentInChildren <AnimatorManager>().PlayTargetAnimation("Riposted", true); } #endregion } }