0
\$\begingroup\$
    public void OnGamePause()
{
    Debug.Log("OnGamePause in PauseController");

    if (rb != null)
    {
        velocity = rb.velocity;
        angularVelocity = rb.angularVelocity;
        Debug.Log("Pause vel. = " + velocity + "Avel. = " + angularVelocity);
        rb.Sleep();
        Paused = true;
    }
}

public void OnGameResume()
{
    Debug.Log("OnGameResume in PauseController");

    if (rb != null)
    {
        Debug.Log("Resume vel. = " + velocity + "Avel. = " + angularVelocity);
        rb.velocity = velocity;
        rb.angularVelocity = angularVelocity;

        rb.WakeUp();
        Paused = false;
    }
}

Console

Can anyone give me any idea what might be changing velocity?

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

Where does OnGamePause come from? the unity documentation reads OnApplicationPause, which is called twice, so i believe that's what causing it. Try copying the vector into a new Vector3, and check if it's set before you do so:

Vector3 velocity = velocity == null ? new Vector3(rb.velocity) : velocity;

also, i don't think the rb.sleep() and rb.wakeup() are necessary when pausing the game. check this link out: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationPause.html

\$\endgroup\$
1
  • \$\begingroup\$ OnGamePause is my own function. It's just called from user input which it turns out I haden't prevented form just calling it repeatedly. \$\endgroup\$ Apr 19, 2018 at 17:03
-1
\$\begingroup\$

Turns out I was just calling OnGamePause many times due to not limiting input.

\$\endgroup\$
1
  • \$\begingroup\$ Don't forget to come back and mark this answer as the accepted one in a couple of days :) \$\endgroup\$
    – Vaillancourt
    Apr 19, 2018 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .