Search Unity

Been building game, put to vita runs SUPER fast, why?

Discussion in 'PSM' started by codejoy, Sep 9, 2014.

  1. codejoy

    codejoy

    Joined:
    Aug 17, 2012
    Posts:
    204
    I cannot figure out why the whole speed of my game seems about 1.5x or 2x faster? I just built it and put on vita and this is what happened, is there some setting I am missing?
    It is almost like the gravity is heavier too. I have a rigidbody2d on my object and its gravity is:
    Gravity scale of 1 mass of one.
    Again runs fine on PC but oddly faster on vita.


    Some code i use for movement for reference:
    Controller moving equals 1 or -1

    Code (csharp):
    1.  
    2.     void Update()
    3.     {
    4.          
    5.         var forceX = 0f;
    6.         var forceY = 0f;
    7.  
    8.         var absVelX = Mathf.Abs (rigidbody2D.velocity.x);
    9.         var absVelY = Mathf.Abs (rigidbody2D.velocity.y);
    10.  
    11.         if (absVelY < .2f) {
    12.             standing = true;
    13.         } else {
    14.             standing = false;
    15.         }
    16.  
    17.         if (controller.moving.x != 0) {
    18.             if (absVelX < maxVelocity.x) {
    19.  
    20.                 forceX = standing ? speed * controller.moving.x : (speed * controller.moving.x * airSpeedMultiplier);
    21.  
    22.                 transform.localScale = new Vector3 (forceX > 0 ? 1 : -1, 1, 1);
    23.             }
    24.             animator.SetInteger ("AnimState", 1);
    25.         } else {
    26.             animator.SetInteger ("AnimState", 0);
    27.         }
    28.  
    29.         if (controller.moving.y > 0) {
    30.             PlayRocketSound();
    31.                         if (absVelY < maxVelocity.y)
    32.                                 forceY = jetSpeed * controller.moving.y;
    33.  
    34.                         animator.SetInteger ("AnimState", 2);
    35.                 } else if (absVelY > 0) {
    36.             animator.SetInteger("AnimState", 3);
    37.                 }
    38.  
    39.         rigidbody2D.AddForce (new Vector2 (forceX, forceY));
    40. }
    41.  
    42.  
     
  2. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    The reason is that your codes running in 'Update' which runs once every frame per second.
    So on PC if your frames per second is 60 the code runs 60 times per second.
    On Vita it may run at 200 fps, so its running 200 times per second, meaning a lot faster results.

    Many ways you can adjust it so it runs the same on ALL devices regardless of power / (fps), but heres one.
    Screen Shot 2014-09-09 at 07.45.24.png
    Times your speed sections by Time.deltaTime (google it to know more about it) but it basically makes all the speeds the same amount regardless of power and fps.

    For example add it here to your forceY and X jetSpeed just plop it under either like so. Nice and simple :)
    Code (CSharp):
    1.  forceY = jetSpeed * controller.moving.y;
    2. forceY *= Time.deltaTime;
    3.  
    4. forceX = standin..m…moving…ultipli… ;
    5. forceX *= Time.deltaTime;
    6.  

    Let me know the results and how it goes!
     
    Last edited: Sep 9, 2014
  3. codejoy

    codejoy

    Joined:
    Aug 17, 2012
    Posts:
    204
    Okay I will try this, I thought something else was off cause it seems like in general via gravity in the game things fall faster...

    does that mean on the vita the gravity scale has to be adjusted too?


    I will try this this evening when I get home though thanks for the reply! :)
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It means like it says in the Unity documentation, use physics in Fixedupdate. The docs are pretty useful ;)
     
  5. codejoy

    codejoy

    Joined:
    Aug 17, 2012
    Posts:
    204
    Fair enough, we have demonstrated my confusedness :) I never had to worry about FixedUpdate before cause systems I were running on it had no noticeable difference, so let me be lazy and use update when it does indeed cleary state rigidbodies, use fixed update! Do'h, Enter Vita making this happy world crash down. I am still fuzzy as to why the gravity itself falls faster, when I have no control (its part of the physics system yes?) I am not applying the gravity in the fixedupdate.
     
  6. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Wheres your gravity code? Or is it using rigid bodies and in built Unity gravity?
    If its done using code apply the
    gravity *= Time.deltaTime;
    to it.
     
  7. codejoy

    codejoy

    Joined:
    Aug 17, 2012
    Posts:
    204
    yah its in unity, actually was a bit of an optical illusion, fixing everything else on speed made the gravity seem normal. Thanks guys, I learned that FixedUpdate is indeed usefull , never saw the use until now running on the vita. Man the vita is screaming