Search Unity

Sprite rotation slowing down game

Discussion in '2D' started by cmb24, Nov 19, 2013.

  1. cmb24

    cmb24

    Joined:
    Oct 3, 2013
    Posts:
    13
    Hey all,

    So I'm trying to rotate my sprite based on the mouse location i.e if the mouse is to the left of the sprite the sprite faces left, and if the mouse is to the right of the sprite the sprite faces to the right.


    The code works, but its making my game really choppy, the sprite doesn't run at its maxSpeed, or jump to its max height, and doesn't fall as fast as gravity...all in relation to before I added this mouse look thing.


    Code (csharp):
    1. // calculate the angle of vector from the mousePosition to the spritePosition in relation to the y-axis
    2.  
    3.  
    4. //clamp the y rotation so it stays 2D
    5. if(angle <90 )
    6.     angle = 0;
    7.  else
    8.        angle = 180;
    9.        
    10. transform.rotation = Quaternion.Euler(0,angle,0);

    This is how I implement it...if I were to comment out the rotation, my sprite moves,jumps,and falls at normal speeds. But when the line is active...is slows all those thing. Could anyone point me in the direction of why this is happening?
     
  2. cmb24

    cmb24

    Joined:
    Oct 3, 2013
    Posts:
    13
    Neverrrrrrmind. I just realized that its flipping every frame even if its facing the right way.
     
  3. dukester

    dukester

    Joined:
    Nov 7, 2012
    Posts:
    14
    But even if the sprite is flipping every frame, that shouldn't slow things down at all. What if that was a desired behavior? You're saying that it couldn't be done (that is, it could, but with slowing down)? Doesn't seem logical. Setting the rotation of a transform (one transform) every frame should have no visible influence on the fps.
    Sounds strange.