#Wanting slow mo as soon as game starts what do i need to change or add?
1 messages · Page 1 of 1 (latest)
you can implement the Start Method, SlowDown there
then start a coroutine, the coroutine should wait a while (if you want) and then stop the slowmo again
don't forget to add a method like OnDestroy where you set the timescale to normal again
So just wanting slow mo straight away
so i dont need the void update with the code then
using System.Collections.Generic;
using UnityEngine;
public class Slowmotion : MonoBehaviour
{
public float slowtime = 0.2f;
void SlowDown()
{
Time.timeScale = Mathf.Lerp(1, slowtime, 5);
}
void Settonormal()
{
Time.timeScale = Mathf.Lerp(0.1f, slowtime, 5);
}
}
where would the on start be?
change the slow down to on start?
using System.Collections.Generic;
using UnityEngine;
public class Slowmotion : MonoBehaviour
{
void OnStart()
{
Time.timeScale = Mathf.Lerp(1, 0.2f, 5);
}
}
you should read the documentation
i was talking about certain event methods that unity will call for you on monobehaviours
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDestroy.html
https://docs.unity3d.com/Manual/Coroutines.html
also important but more generally:
https://docs.unity3d.com/Manual/ScriptingConcepts.html
https://docs.unity3d.com/Manual/ScriptingImportantClasses.html
so yeah you could just call your SlowDown method inside start
and why do you use a lerp?
when you slow down, you assign your slowtime to Time.timeScale
when you set back to normal you assign 1 again Time.timeScale = 1f;
also, in case you find it useful, I'll also leave a link to general coding resources here (C# etc)
since it is important to understand some basic coding concepts and logical concepts since you will always need them when doing stuff in unity, and it helps to understand tutorials better too.
I don't know if you need this ofc, maybe you already know some coding basic
<#old_unity message>
and in your current code, SlowDown() method will actually set the timescale to be a higher vaue than the timescale you set in Settonormal
and in Settonormal, with these values, you don't perfectly set the timescale to 1, so that's a logical mistake
Also, if you're changing your timescale, you'll want to change Time.fixedDeltaTime by the same amount, or physics and things running in FixedUpdate() will break
I'd say it depends, because what happens when you adjust fixedDeltaTime is that you now introduce smaller steps between simulation
you can adjust it if you want the same amount of fixed update cycles than usual when the game slows down
or you don't adjust it, get fewer updates (less than before) but get physical responses that are closer to or identical to how the responses were during unscaled time.
for the sake of smoothness though for simulating and visualization, I agree, it can be a good idea
If you don't do this, rigidbodies will look super weird.
Or you can set your physics update to not be tied to the fixed step, which also fixes the issue