How to have slowmotion affect everything but the player without using Time.deltaTime for the player
Hello everyone, I have a player movement script that works very well right now and I'm in a bit of a time crunch so rebuilding everything isn't exactly possible right now. I was wondering how to have slow motion affect everything in the scene but the player. I'm currently halfway there, as the player can move left and right normally, but they still move up and down in slow motion. Here is my movement code:
void FixedUpdate()
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
Here is my jumping code:
void FixedUpdate () {
if(rb.velocity.y<0) {
rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
} else if((rb.velocity.y > 0) && !Input.GetButton("Jump")) {
rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}
}
And here is my slow motion code:
private void Update()
{
Time.timeScale = (1f / slowdownLength);
Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
}
public void Slowdown() {
Time.timeScale = slowdownFactor;
Time.fixedDeltaTime = Time.timeScale * 0.02f;
}
Then, in the player controller, I use a coroutine to apply the slow motion for a set amount of time:
if (Input.GetButtonDown("SlowButton"))
{
StartCoroutine(Slow());
timeManager.Slowdown();
}
}
IEnumerator Slow() {
float timePassed = 0;
speed /= timeManager.slowdownFactor;
while (timePassed < 3) {
timeManager.Slowdown();
timePassed += Time.unscaledDeltaTime;
yield return null;
}
Time.timeScale = 1;
speed = 8;
}
By dividing the speed by the slowdown factor, I can get the player to be able to move left and right at a normal pace, but I don't know how to achieve this for movement on the y axis. Can anyone offer any ideas?
Your answer
![](https://koobas.hobune.stream/wayback/20220612175207im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Navigation in VR Mode?!! 0 Answers
Making a counter that does not reflect on time 2 Answers
OnTriggerEnter has a weird bug, help me pls 1 Answer
c# How to delay code for animator animation to finish 2 Answers
Check rotation of an obstacle 0 Answers