Slow Motion Issues!
Hi Guys,
I am currently having issues with trying to "temporarily" slow down time after the player is hit. I have read around the forums and answers and can't figure out why my code isn't working.
//These Methods are in the same Class..
public void TakeDamage(int atkdmg, int animeControllerNum) {
hurtIdentifier = animeControllerNum;
currentHealth -= atkdmg;
healthSlider.value = currentHealth;
_tookDamage = true;
timeScaleTimer = scaleTimerVal; // (scaleTimerVal set to 2f) to set the timer to control when the game should go back to regular 1f time scale
_turnSlowMoOn = true;
}
void Update() {
timeScaleTimer -= Time.deltaTime;
if (timeScaleTimer <= 0) {
timeScaleTimer = 0;
_turnSlowMoOn = false;
}
if (_turnSlowMoOn) {
if (Time.timeScale == 1f) {
Time.timeScale = .5f;
}
else {Time.timeScale = 1f;
Time.fixedDeltaTime = .02f * Time.timeScale;
}
}
When you ask this sort of question you should describe the behavior you're encountering.
Where's the sense in setting Time.timeScale to 1 when you've already checked that it is 1. Why are you changing Fixed delta time, as it's tied to deltaTime? "Note that the fixedDeltaTime interval is with respect to the in-game time affected by timeScale."
I am not encountering anything.. that is why I am asking the question..
I am changing FixedDelta time so that the physics engine can be updated as well.(http://docs.unity3d.com/ScriptReference/Time-timeScale.html).
Thanks for responding
I am fairly new to the Game Program$$anonymous$$g world.
Answer by ryan_unity · Mar 25, 2016 at 09:21 PM
Hey, it looks like the time scale will be flipping between 1 and 0.5 each frame when _turnSlowMoOn is true. Can you try changing it to something like:
if (_turnSlowMoOn) {
Time.timeScale = 0.5f;
}
else {
Time.timeScale = 1.0f;
}
Time.fixedDeltaTime = 0.02f * Time.timeScale;
Your answer
Follow this Question
Related Questions
Load scene after time 1 Answer
Is UI affected by time scale ? 1 Answer
Respawn issues 2 Answers
How to Make Timer (Score) Count Up Faster? 1 Answer
Why is my Unity Game crashing whenever Time Left is close to 0? 0 Answers