Search Unity

Pause and resume game -- kinematic vs physics

Discussion in 'Scripting' started by brainfire9, Nov 25, 2015.

  1. brainfire9

    brainfire9

    Joined:
    Feb 3, 2015
    Posts:
    11
    I have been working on a Breakout style game for Android, currently lettings physics handle the ball bouncing all over. I also have objects (e.g. points, powerups) that can fall from bricks once they've been destroyed, just letting gravity do the work on the object Rigidbody2D at the moment. I would like to pause the game when the Options menu button is tapped, but setting Time.timeScale to 0 actually pauses the animation of my Options menu sliding into place.

    Taking a different approach, if I create a temporary float and Vector2, store the Rigidbody2D angularVelocity and velocity, zero them out on the rigidbody then set isKinematic to true, it pauses the ball just fine. I can then "unpause" by setting the velocity and angularVelocity back, isKinematic = false, and everything seems to be working.

    Except for the objects that drop from the broken bricks.

    I've started to address this by creating a tag called 'freezable', thinking I can go through the array of objects on the screen, store all values, and handle it the same way I stop the ball from moving ... this doesn't seem very efficient though.

    I thought of just setting the objects that drop (powerups and stuff) to always be kinematic, then I won't have to store their velocities (just decide what speed all objects should drop at), but do you take a hit on performance by mixing physics and kinematic objects?

    Would it be better to set EVERYTHING to kinematic?

    Many thanks for any suggestions!
     
  2. Azmar

    Azmar

    Joined:
    Feb 23, 2015
    Posts:
    246
    uTime asset package, has pause/resume game and only 2$ on asset store...could save you a lot of trouble? I tested it when it was free and worked fine for me!
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    passerbycmc and BenZed like this.
  4. brainfire9

    brainfire9

    Joined:
    Feb 3, 2015
    Posts:
    11
  5. brainfire9

    brainfire9

    Joined:
    Feb 3, 2015
    Posts:
    11
    I'll have to check out the asset, if I can ever get this game finished I wanted to play around with the timescale stuff more in an infinite runner.

    Thanks!