- Home /
Slow Mo effect with Time.timeScale? Dont understand Lerp and Corutines...
I allready have a working code to achieve a slow mo effect... It falls down and then up- but, I think it can be made way cooler by someone who understands coroutines and lerp properly (this person is not me);
How could I implement an effect similar to this one by using Lerp or Slerp? thank you for the help :)
public class TimeManipulation : MonoBehaviour {
KeyCode timeManipualtionKey;
public bool manipulatingTime;
public bool manipulatingDown;
public bool manipulatingUp;
public float manipulationRate;
public float timeManipulationDown = .5f;
public float lerpSpeed = 10;
public float durationOfManipulation = 2;
float it = 1;
float increment = .05f;
void OnEnable()
{
timeManipualtionKey = this.GetComponent<Attributes> ().timeManipulation;
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown (timeManipualtionKey)) {
manipulatingTime = true;
manipulatingDown = true;
}
if (manipulatingTime) {
if (manipulatingDown) {
if (it >= .5f) {
print ("manipulating Down");
it -= increment;
Time.timeScale = it;
Time.fixedDeltaTime = 0.02f* Time.timeScale;
} else {
print ("finished manipulation Down");
manipulatingDown = false;
StartCoroutine (TimeInTheZone ());
}
}
if (manipulatingUp) {
if (it <= 1) {
print ("starting manipulating up");
it += increment;
Time.timeScale = it;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
} else {
print ("manipulation ended");
manipulatingUp = false;
manipulatingTime = false;
}
}
}
}
IEnumerator TimeInTheZone()
{
print ("starting wait");
yield return new WaitForSeconds (1);
print ("wait ended");
manipulatingUp = true;
yield return null;
}
}
I don't think lerp or slerp would really be applicable here. If that code works I would just stick with it.
But I would stay away from using fixedDeltaTime. That just sets the intervals at which physics update. But if you're scaling down the timeScale, there's no need to mess with the way physics update, since it's reliant on timeScale to begin with. I would also put it in a regular Update function rather than a FixedUpdate. Since FixedUpdate updates with the physics, and is really only used to make things play nice with physics.
Answer by JoshDangIt · May 10, 2016 at 05:21 PM
Unity's scripting reference does an awful job of explaining Lerping. Here's a guide I found that does a better job of explaining it.
http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly
Even though it's a guide on Vector3.Lerp, Mathf.Lerp is basically the same concept.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080506im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
object's children not moving with it when using a Lerp-ing coroutine 0 Answers
re use a charged ability that isn't at 100 percent? 1 Answer
Lerping alpha with coroutine only lerping first time it is triggered by event 1 Answer
[HELP] How to make camera smooth change position while follow object? 1 Answer