The question is answered, right answer was accepted
Temporarily disable my player input?
I was testing out my pause function which I thought worked like a charm but I figured out if the player pauses, then holds the movement button (in whatever direction) it uses all the build up momentum from holding the movement button when the player unpauses launching them in whatever direction.
Is there a way to temporarily disable the player input while paused?
Here is my pause function if that helps:
//Pausing and unpausing
if (Input.GetKeyDown (KeyCode.P))
{
if (Time.timeScale == 1) {
Time.timeScale = 0;
} else {
Time.timeScale = 1;
}
}
So I tried something but it doesn't work but maybe it'll help in helping me(if that makes sense).
I added(tried making them private Vector3 but that didn't change anything):
static Vector3 savedVelocity; static Vector3 savedAngularVelocity;
I changed the pause function like this:
//Pausing and unpausing
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.P))
{
if (Time.timeScale == 1) {
Time.timeScale = 0;
savedVelocity = rb.velocity;
savedAngularVelocity = rb.angularVelocity;
rb.is$$anonymous$$inematic = true;
} else {
Time.timeScale = 1;
rb.velocity = savedVelocity;
rb.angularVelocity = savedAngularVelocity;
rb.is$$anonymous$$inematic = false;
}
}
Sadly all of this did nothing.
Answer by unity_bcUiA2t7GqTPBA · Oct 06, 2017 at 10:45 AM
So this probably shouldn't have been that difficult but I have done it:
if (Input.GetKeyDown (KeyCode.P))
{
if (Time.timeScale == 1) {
savedVelocity = rb.velocity;
savedAngularVelocity = rb.angularVelocity;
rb.isKinematic = true;
Time.timeScale = 0;
} else {
Time.timeScale = 1;
rb.isKinematic = false;
rb.velocity = Vector3.zero;
rb.velocity = savedVelocity;
rb.angularVelocity = Vector3.zero;
rb.angularVelocity = savedAngularVelocity;
Also add two private Vector3's, one called savedVelocity and one called savedAngularVelocity.
May this help someone else out.
Follow this Question
Related Questions
how to make mathf.pingpong not from 0 3 Answers
How to pass in an Integer 1 Answer
[SOLVED] NullReferenceException in a script that calls another object's script variable 1 Answer
Manual GUI Refresh 0 Answers
I can't move my player in a fps? 1 Answer