Search Unity

[HELP] Trouble with Physics2D.Simulate, Physics2D.Step and Physics2D.SyncTransforms

Discussion in 'Physics' started by SuperHadees, Dec 6, 2017.

  1. SuperHadees

    SuperHadees

    Joined:
    Jul 17, 2017
    Posts:
    5


    Here is my problem.
    I'm making an Android Game, and i don't know what is going.
    First 20 seconds of gameplay, my game is running at 30 FPS, then, the FPS got a jump to 120 FPS and everything is normal. That happens when I try in my PC.

    When I convert to APK and try my game in my cellphone, is lagging hard. I try in a LG K10 and in a Sony Xperia XA. In both cellphone my game is running too lag.

    I think the problem is with the Polygon collider in my character.


    I try to change it, but nothings happens.



    Starts like this, 30 FPS.


    This is my character script, for moving, and everything.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ControladorPersonaje : MonoBehaviour {
    6.     public float fuerzaSalto = 100f;
    7.  
    8.     public bool enSuelo = true; // Porque se empieza en el suelo.
    9.  
    10.     public Transform comprobadorSuelo;
    11.  
    12.     float comprobadorRadio= 0.07f;
    13.     public LayerMask mascaraSuelo;
    14.  
    15.     private bool dobleSalto = false;
    16.  
    17.     private bool corriendo = false; // Falso porque empezara quieto inicialmente.
    18.     public float velocidad= 10f;
    19.  
    20.  
    21.  
    22.  
    23.     // Use this for initialization
    24.     void Start () {
    25.  
    26.      
    27.     }
    28.     void FixedUpdate ()
    29.     {
    30.      
    31.         if (corriendo == true) {
    32.             GetComponent<Rigidbody2D> ().AddForce (Vector2.right * velocidad+GetComponent<Rigidbody2D> ().velocity);
    33.  
    34.  
    35.      
    36.         }
    37.  
    38.         if (enSuelo) {
    39.             dobleSalto = false;
    40.         }
    41.  
    42.    
    43.     }
    44.     // Update is called once per frame
    45.     void Update () {
    46.  
    47.         if(Input.GetMouseButtonDown(0)){
    48.             if(corriendo==false){
    49.                 corriendo = true;
    50.                 NotificationCenter.DefaultCenter().PostNotification (this, "PersonajeEmpiezaACorrer");
    51.      
    52.                 }
    53.  
    54.         else{
    55.             if(enSuelo || !dobleSalto){
    56.                     GetComponent<Rigidbody2D>().AddForce(new Vector2(velocidad,(fuerzaSalto)));
    57.  
    58.                 if(!dobleSalto && !enSuelo){
    59.                         dobleSalto = true;
    60.                         }
    61.                 }
    62.             }
    63.  
    64.         }
    65.  
    66.         Animator anim = GetComponent<Animator> ();
    67.         anim.SetFloat ("VelX", GetComponent<Rigidbody2D>().velocity.x);
    68.  
    69.         enSuelo = Physics2D.OverlapCircle (comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
    70.         anim.SetBool ("isGrounded", enSuelo);
    71.     }
    72. }
    73.  
    74.    
    75.  
    I move the Animator line command to void Update () instead of Fixedupdate (), because Physics2D.Overlapcircle() was spiking in my Profiler.

    Any suggestions are welcome.
    I'm just 17 and don't know too much about scripting, but this proyect got me so engaged that i want to finish this.

    Thank you for reading :)