Search Unity

2D fps + moving the objects

Discussion in 'Editor & General Support' started by gromilQaaaa, Dec 3, 2013.

  1. gromilQaaaa

    gromilQaaaa

    Joined:
    Oct 28, 2013
    Posts:
    14
    I'm new in unity, and my english is bad, so sorry first of all :)

    I'm making a 2D iOS game where the player moves to the right and the enemy comes from the right side of the screen. I've downloaded the demo version that has Fixed Timestep = 0,02 (50fps). The internet says i should make it 30 or 60fps for iOS. Well I changed that in my project to Fixed Timestep = 0,033 (30fps) and added:
    Code (csharp):
    1. int frameRate = 30;
    2. public void Start () {  
    3. Time.captureFramerate = frameRate;      
    4. }
    but the player and enemys started to move strange - they all stop periodically.

    After that I read that if I use FixedUpdate () I don't need the frameRate - so I just deleted that. Now my player moves a bit snatchy and I just want some normal smooth. Here's how I move the player and enemy:
    Code (csharp):
    1.        
    2. void FixedUpdate ()
    3.         {
    4.             if(rigidbody2D.velocity.x < maxSpeed)
    5.                 rigidbody2D.AddForce(Vector2.right * current_moveForce);
    6.    
    7.             if(Mathf.Abs(rigidbody2D.velocity.x) > maxSpeed)
    8.                         rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * maxSpeed, rigidbody2D.velocity.y);
    9.  
    Whatever I do the objects still dont move smooth. Can anyone tell me what am I doing wrong? :)
    ps: Im' trying to make the player and the enemy stop OnCollisionEnter2D, but they are pushing each other. As I understand the only way to fix that is to manage their mass, yes?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Fixed timestep is for physics, and has no effect on the visible framerate. Time.captureFramerate is only to be used for capturing video; do not use it in a released game because it makes it run as fast as possible.

    --Eric