public void OnHurt(TakeDamager damager, TakeDamageable damageable) { //if the player don't have control, we shouldn't be able to be hurt as this wouldn't be fair if (!PlayerInput.Instance.HaveControl) { return; } UpdateFacing(damageable.GetDamageDirection().x > 0f); damageable.EnableInvulnerability(); m_Animator.SetTrigger(m_HashHurtPara); //we only force respawn if health > 0, otherwise both forceRespawn & Death trigger are set in the animator, messing with each other. if (damageable.CurrentHealth > 0 && damager.forceRespawn) { m_Animator.SetTrigger(m_HashForcedRespawnPara); } m_Animator.SetBool(m_HashGroundedPara, false); hurtAudioPlayer.PlayRandomSound(); //if the health is < 0, mean die callback will take care of respawn if (damager.forceRespawn && damageable.CurrentHealth > 0) { //StartCoroutine(DieRespawnCoroutine(false, true)); } }
public Vector2 GetHurtDirection() { Vector2 damageDirection = damageable.GetDamageDirection(); if (damageDirection.y < 0f) { return(new Vector2(Mathf.Sign(damageDirection.x), 0f)); } float y = Mathf.Abs(damageDirection.x) * m_TanHurtJumpAngle; return(new Vector2(damageDirection.x, y).normalized); }