public void getHitBy(moveData move, Transform attacker) { AttatchedCharacter = transform.root; //Cannot be hit while time travelling if (AttatchedCharacter.GetComponent <PlayerManager>().GetState() == PlayerState.TimeTravelling) { return; } //If hit during parry, reflect attack if (AttatchedCharacter.GetComponent <PlayerManager>().GetState() == PlayerState.Parrying) { attacker.root.GetComponent <Hurtbox>().getHitBy(parryData, transform); GetComponent <Animator>().SetTrigger("Forward-Normal"); return; } Vector3 totalKnockback = move.baseKnockBack + (move.knockBackGrowth * AttatchedCharacter.GetComponent <PlayerManager>().getPercent()); AttatchedCharacter.GetComponent <PlayerManager>().setHitStun(move.hitStun); AttatchedCharacter.GetComponent <PlayerManager>().addDamage(move.damage); AttatchedCharacter.GetComponent <Rigidbody>().velocity = Vector3.zero; AttatchedCharacter.GetComponent <Rigidbody>().AddForce(totalKnockback); GetComponent <Animator>().SetTrigger("Flinch"); //Set current Attacker as the last player that hit you attacker.GetComponent <PlayerManager>().AddTimeJuice(0.1f); AttatchedCharacter.GetComponent <PlayerManager>().updateLastHitBy(attacker); // When you get hurt StartCoroutine(MakeHitSparks(move.hitStun, AttatchedCharacter.GetComponent <PlayerManager>().getPercent())); }
//Used to apply the effects of an attack that connected with the opponent //Currently applies same effects for each move, but if we add some weirder moves this could be useful public void collisionedWith(Collider collider, string move) { //FIXME: Lazy Way of making knockback apply in the correct direction moveData inputData = moveDictionary[move]; inputData.baseKnockBack = Quaternion.Euler(0, (float)transform.GetComponent <PlayerManager>().getPlayerOrientation(), 0) * inputData.baseKnockBack; inputData.knockBackGrowth = Quaternion.Euler(0, (float)transform.GetComponent <PlayerManager>().getPlayerOrientation(), 0) * inputData.knockBackGrowth; //Cannot hit your own parent if (collider.transform.root == GetComponent <PlayerManager>().getEchoParent()) { return; } else { collider.transform.root.GetComponent <Hurtbox>().getHitBy(inputData, transform); } }