- Home /
Question by
deadeye26 · Mar 14, 2021 at 08:37 PM ·
physics2d-platformerrigidbody2dtimescale
How to make a gameobject unaffected by time scale?
So I have this is script that both makes the player move and, when pressing a key, it slows down time. I want the player to not be affected by this however but I'm unsure of what to do to achieve so. This is the code:
if (Input.GetKeyUp(KeyCode.X))
{
trailRend.emitting = false;
Time.timeScale = 1;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
if (Input.GetKeyDown(KeyCode.X))
{
trailRend.emitting = true;
Time.timeScale = 0.5f;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
And this is the code to move the player:
MainChar.SetFloat("runStart", Mathf.Abs(rigidBody.velocity.x));
float movingX = Input.GetAxis("Horizontal");
rigidBody.AddForce(Vector2.right * Speed * movingX);
Someone told me to use unscaled delta time but I can't figure out where to put it exactly. Could someone give me some pointers?
Comment