void Update() { if (GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength) == CameraRecoilSetting.Off || GameManager.IsGamePaused) // prevent continuous spinning on pause { return; } else { cameraRecoilSetting = GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength); } int healthLost = vitalsDetector.HealthLost; float healthLostPercent = vitalsDetector.HealthLostPercent; // Detect Health loss if (healthLost > 0) { const float minPercentThreshold = 0.02f; // useless to do it for less than a certain percentage if (healthLostPercent > minPercentThreshold) { // Start swaying and timer countdown bSwaying = true; //Debug.Log("Percent loss: " percentLost); // longer timer for more health percent lost timerStart = CalculateTimerStart(healthLostPercent); timer = timerStart; // get a random unit vector axis for the sway direction SetSwayAxis(); //Debug.Log("Start Swaying"); } } // do swaying if (bSwaying) { const float timerSpeed = 2f * Mathf.PI; //how quickly the player's view recoils and how quickly it is finished recoiling. timer -= Time.deltaTime * timerSpeed; // get new view rotation float rotationScalar = CalculateRotationScalar(healthLost); playerCamTransform.Rotate(GetRotationVector(healthLost, rotationScalar)); // keep swaying as long as there's time left bSwaying = (timer > 0); } }
protected const float baseMaxRecoilSeverity = 50f; // may need to adjust void Start() { playerCamTransform = GameManager.Instance.MainCamera.transform; // Get starting health and max health if (GameManager.Instance != null && GameManager.Instance.PlayerEntity != null) { ResetRecoil(); } cameraRecoilSetting = GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength); // Use events to capture a couple of edge cases StreamingWorld.OnInitWorld += StreamingWorld_OnInitWorld; SaveLoadManager.OnStartLoad += SaveLoadManager_OnStartLoad; }
protected const float baseMaxRecoilSeverity = 50f; // may need to adjust void Start() { playerCamTransform = GameManager.Instance.MainCamera.transform; vitalsDetector = GetComponent <VitalsChangeDetector>(); // Get starting health and max health if (GameManager.Instance != null && GameManager.Instance.PlayerEntity != null) { ResetRecoil(); } cameraRecoilSetting = GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength); // Use events to capture a couple of edge cases StreamingWorld.OnInitWorld += StreamingWorld_OnInitWorld; SaveLoadManager.OnStartLoad += SaveLoadManager_OnStartLoad; DaggerfallCourtWindow.OnCourtScreen += DaggerfallCourtWindow_OnCourtScreen; }
void Update() { if (GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength) == CameraRecoilSetting.Off || GameManager.IsGamePaused) // prevent continuous spinning on pause { return; } else { cameraRecoilSetting = GetRecoilSetting(DaggerfallUnity.Settings.CameraRecoilStrength); } // Check max health hasn't changed - this can indicate user has loaded a different character // or current character has levelled up or changed in some way and the cached health values need to be refreshed. // Just reset values and exit for this frame as the current relative health lost calculation is not valid when MaxHealth changes. int maxHealth = GameManager.Instance.PlayerEntity.MaxHealth; int currentHealth = GameManager.Instance.PlayerEntity.CurrentHealth; if (maxHealth != previousMaxHealth) { ResetRecoil(); return; } // Detect Health loss int healthLost = previousHealth - currentHealth; if (healthLost > 0) { const float minPercentThreshold = 0.02f; float percentLost = (float)healthLost / maxHealth; // useless to do it for less than a certain percentage if (percentLost >= minPercentThreshold) { // Start swaying and timer countdown bSwaying = true; //Debug.Log("Percent loss: " percentLost); // longer timer for more health percent lost timerStart = CalculateTimerStart(percentLost); timer = timerStart; // get a random unit vector axis for the sway direction SetSwayAxis(); //Debug.Log("Start Swaying"); } } // reset previous health to detect next health loss previousHealth = currentHealth; // do swaying if (bSwaying) { const float timerSpeed = 2f * Mathf.PI; //how quickly the player's view recoils and how quickly it is finished recoiling. timer -= Time.deltaTime * timerSpeed; // get new view rotation float rotationScalar = CalculateRotationScalar(healthLost); playerCamTransform.Rotate(GetRotationVector(healthLost, rotationScalar)); // keep swaying as long as there's time left bSwaying = (timer > 0); } }