public void TakeDamages(float fDamages, Vector3 orientation, float fEjectionFactor) { // // Check for invincibility first if (bonusHolder.IsBonusEnabled(EBonusType.invincibility)) { // // TODO maybe do something in shadergraph return; } // // Then take damages percentage = Mathf.Min(percentage + fDamages, 999.0f); // // Play damage sound if (m_bCanPlayDamageSound) { int iSound = Random.Range(0, m_aAudioClipsDamage.Length); m_audioSource.PlayOneShot(m_aAudioClipsDamage[iSound], 0.2f); m_bCanPlayDamageSound = false; Invoke("ResetCanPlayDamageSound", 0.4f); } // // Notify death if (null != UiManager) { UiManager.OnPlayerDamageTaken(this); } // Ejection based on percentage orientation.Normalize(); // convert damages to [-2,5] for exponential // Linear ratio conversion ((old_value - old_min) / (old_max - old_min)) * (new_max - new_min) + new_min float fRangedVal = (percentage / 999) * 7; float fForceFactor = Mathf.Exp(fRangedVal); //Debug.Log("percentage " + percentage); //Debug.Log("fRangedVal " + fRangedVal); //Debug.Log("fForceFactor " + fForceFactor); //Debug.Log("fEjectionFactor " + fEjectionFactor); rigidBody.AddForce(orientation * fForceFactor * (fEjectionFactor * 2.0f), ForceMode.Impulse); }
// Update is called once per frame private void Update() { // // Timers m_fWaftTimer += Time.deltaTime; // // Compute the grounded attribute ComputeGrounded(); // // UpdateCharacterDirection(m_inputActionMove.ReadValue <float>()); // // if (m_inputActionMove.ReadValue <float>() != 0.0f) { GetComponent <Animator>().SetBool("bRunning", true); // // Play the grounded sound if (m_bCanPlayStepSound && m_bGrounded) { int iSound = Random.Range(0, m_aAudioClipsSteps.Length); m_audioSource.PlayOneShot(m_aAudioClipsSteps[iSound], 0.2f); m_bCanPlayStepSound = false; Invoke("ResetCanPlayStepSound", 0.2f); } } else { GetComponent <Animator>().SetBool("bRunning", false); } GetComponent <Animator>().SetBool("bFall", false); // // if (m_inputActionShoot.ReadValue <float>() != 0.0f) //< We use ReadValue here to trigger the action while the key is pressed { if (null != m_weaponHolder.GetCurrentWeapon()) { bool bUnlimitedAmmo = m_bonusHolder.IsBonusEnabled(EBonusType.unlimited_ammo); m_weaponHolder.GetCurrentWeapon().GetComponent <WeaponShot>().Shoot(m_fWeaponDamageFactor, bUnlimitedAmmo); } else { if (m_bCanPlayNoWeaponSound) { m_audioSource.PlayOneShot(m_audioClipNoWeapon, 0.2f); m_bCanPlayNoWeaponSound = false; Invoke("ResetCanPlayNoWeaponSound", 0.6f); } } } // // if (m_inputActionThrow.triggered) { m_weaponHolder.DropWeapon(); } if (m_inputActionJump.triggered) { m_bJumpedTriggered = true; } if (m_inputActionWaft.triggered && m_fWaftTimer >= m_fWaftCooldown && !m_bIsWafting) { StartWaft(); } }