- Home /
Velocity and Animator change while game is Paused
Hey everyone :)
I'm making a 2D-Platform game, everything was going well until I noticed 2 DIFFERENT problems regarding paused state (Time.timeScale = 0)
1) If I press 'space' while game is paused, player jumps right after I unpause (Time.timeScale = 1) the game.
For jump I use:
GetComponent<Rigidbody2D>.AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
I checked rigidbody's info and indeed even if game is Paused, everytime I press 'space' velocity.y adds 5 and right after I unpause, my player performs the jump.
(Yes I can spam space and then do a super jump lol)
I don't understand why my velocity can change while game is paused.
2) Player's animation change while game is paused.
I'm using very simple animation system (2 states). 'Idle' and 'Moving'. They normally alter if my xmovement = Input.GetAxis("Horizontal")' is equal or different to 0.
If I pause my game while xmovemenet is '1', then if I press 'left' while game is paused, xmovement returns to 0 (that means my character returns to IDLE while paused). Same with the oppossite direction (-1 and right).
I have to mention 2 things about it:
1) While xmovement = 0, then it cannot change to 1 or -1 (while paused I mean). It only goes TO zero.
2) If I pause while xmovement = 0.49543234 (for example) then by clicking left it returns back to 0.
Sorry if my questions are simple, but I'm really confused not about how to find a 'different' way, but to find out why this is happening.
Thanks in advance :)
Answer by $$anonymous$$ · Nov 13, 2020 at 07:31 AM
You shouldn't register input when your game is paused.
Thanks. I put my input checks under an if (Time.timeScale != 0 ) statement and it worked fine!
if (Time.timeScale != 0)
{
horizontalmove = Input.GetAxis("Horizontal");
Jump();
}
Just for educational purposes do you know why x-axis input could go to 0, but then couldn't go back to 1 or -1? (while paused)
Your answer
Follow this Question
Related Questions
What is the "jump"/ Y axis? How It's called in scripting? 1 Answer
ForceMode.Impulse Doesnt always fire. 2 Answers
Model stays at the end of my animation D:? 0 Answers
Animation axis of UI element reversed (bug?) 0 Answers
Error console animator 0 Answers