public bool CheckForParry() { EnemyStates ParryTarget = null; Vector3 Orgin = transform.position; Orgin.y += 1; Vector3 RayDir = transform.forward; RaycastHit hit; if (Physics.Raycast(Orgin, RayDir, out hit, 3f, IgnoreLayers)) { ParryTarget = hit.transform.GetComponentInParent <EnemyStates>(); } if (ParryTarget == null) { return(false); } /* if(ParryTarget.ParriedBY == null) * return false;*/ /* float distnace = Vector3.Distance(ParryTarget.transform.position,transform.position); * if(distnace > 3f) * * return false;*/ Vector3 dir = ParryTarget.transform.position - transform.position; dir.Normalize(); dir.y = 0; float _angle = Vector3.Angle(transform.forward, dir); if (_angle < 60) { Vector3 targetPos = -dir * ParryOffset; targetPos += ParryTarget.transform.position; transform.position = targetPos; if (dir == Vector3.zero) { dir = -ParryTarget.transform.forward; } Quaternion ERotation = Quaternion.LookRotation(-dir); Quaternion ourRot = Quaternion.LookRotation(dir); ParryTarget.transform.rotation = ERotation; transform.rotation = ourRot; ParryTarget.IsGettingParried(); Anim.CrossFade("Parry", 0.01f); CanMove = false; InAction = true; ParryIsOn = false; EnemyTarget = null; return(true); } return(false); }
bool CheckForParry(Action slot) { if (slot.canParry == false) { return(false); } EnemyStates parryTarget = null; Vector3 origin = transform.position; origin.y += 1; Vector3 rayDir = transform.forward; RaycastHit hit; if (Physics.Raycast(origin, rayDir, out hit, 2, ignoreLayers)) { parryTarget = hit.transform.GetComponentInParent <EnemyStates>(); } if (parryTarget == null) { return(false); } if (parryTarget.parriedBy == null) { return(false); } //direction calculated from the player to the enemy. Vector3 dir = parryTarget.transform.position - transform.position; dir.Normalize(); dir.y = 0; float angle = Vector3.Angle(transform.forward, dir); if (angle < 60) { Vector3 targetPosition = -dir * parryOffset; targetPosition += parryTarget.transform.position; transform.position = targetPosition; if (dir == Vector3.zero) { dir = -parryTarget.transform.forward; } Quaternion eRotation = Quaternion.LookRotation(-dir); Quaternion ourRot = Quaternion.LookRotation(dir); parryTarget.transform.rotation = eRotation; transform.rotation = ourRot; parryTarget.IsGettingParried(slot, inventoryManager.GetCurrentWeapon(slot.mirror)); canAttack = false; onEmpty = false; canMove = false; inAction = true; anim.SetBool("mirror", slot.mirror); anim.SetFloat("parrySpeed", 1); anim.CrossFade("parry_attack", 0.2f); lockOnTarget = null; return(true); } return(false); }
bool CheckForParry(Action slot) { EnemyStates parryTarget = null; Vector3 origin = transform.position; origin.y += 1; Vector3 rayDir = transform.forward; RaycastHit hit; if (Physics.Raycast(origin, rayDir, out hit, 3, ignoreLayers)) { parryTarget = hit.transform.GetComponentInParent <EnemyStates>(); } if (parryTarget == null) { return(false); } if (parryTarget.parriedBy == null) { return(false); } /* float dis = Vector3.Distance(parryTarget.transform.position, transform.position); * * if (dis > 3) * return false;*/ Vector3 dir = parryTarget.transform.position - transform.position; dir.Normalize(); dir.y = 0; float angle = Vector3.Angle(transform.forward, dir); if (angle < 60) { Vector3 targetPosition = -dir * parryOffset; targetPosition += parryTarget.transform.position; transform.position = targetPosition; if (dir == Vector3.zero) { dir = -parryTarget.transform.forward; } Quaternion eRotation = Quaternion.LookRotation(-dir); Quaternion ourRot = Quaternion.LookRotation(dir); parryTarget.transform.rotation = eRotation; transform.rotation = ourRot; parryTarget.IsGettingParried(); canMove = false; inAction = true; anim.SetBool(StaticStrings.mirror, slot.mirror); anim.CrossFade(StaticStrings.parry_attack, 0.2f); lockOnTarget = null; return(true); } return(false); }