Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by CAH4AC · Mar 06, 2016 at 07:26 PM · jerking

How to get a smooth movement of GameObjects

Hi, All. I created simple 2D project. In the editor it works fine. But when I run it on devices (Android, iOS), it slows down periodically. Movement is not smooth, objects jerk. In android FPS is 60, but periodically it drops to 40 and game freezing. Unity 5.3.3f1 Personal. Project is very simple: 1 prefab with Rigidbody2d and 3 scripts, but I can't understand the problem. Can somebody help?

CreateGame.cs:

 using System;
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 
 public class CreateGame : MonoBehaviour {
 
     public GameObject cube;
 
     private List<GameObject> listCubes;
     private int CUBES_COUNT = 40;
 
     // Use this for initialization
     void Start () {
 
         //Create Object Pool
         createPool ();
 
         //Get Cube from Pool
         Invoke ("CreateCube", 0f);
     }
 
     //Create Pool
     void createPool(){
         for (int i = 0; i < CUBES_COUNT; i++) {
             ObjPool.instance.cubes.putObj((GameObject)Instantiate(cube));
         }
     }
 
     void CreateCube()
     {
         //get Cube from pool
         ObjPool.instance.cubes.getObj ();
         //Invoke itself
         Invoke("CreateCube", UnityEngine.Random.Range (0.2f, 0.5f));
     }
         
     // Update is called once per frame
     void Update () {
         //get Android back button
         if (Application.platform == RuntimePlatform.Android) {if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); }}
     }
 }
 


ObjectPool.cs:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 
 public class ObjPool : MonoBehaviour {
 
     public static ObjPool instance { get; private set; }
 
 
     public class Pool {
         private List<GameObject> pool;
         public Pool(){
             pool = new List<GameObject>();
         }
 
         public void putObj (GameObject obj){
             obj.SetActive (false);
             pool.Add (obj);
         }
             
         public GameObject getObj(){
             if (pool.Count > 0)
             {
                 GameObject pooledObject = pool[0];
                 pool.RemoveAt(0);
                 pooledObject.transform.parent = null;
                 pooledObject.SetActive(true);
 
                 return pooledObject;
             }
             return null;
         }
     }
 
     public Pool cubes;
 
     void OnEnable()
     {
         instance = this;
         cubes = new Pool ();
     }
 
 
 }

MoveCube.cs: using UnityEngine; using System.Collections;

 public class MoveCube : MonoBehaviour {
 
 
     private float range = 4f;
 
     private Vector2 velocity;
 
     private Vector3 initPosition;
 
     private Rigidbody2D rigidBody2d;
 
 
     void Start () {
         rigidBody2d = GetComponent<Rigidbody2D> ();
 
     }
 
 
     void OnEnable(){
         Init ();
 
     }
 
     public void Init()
     {
         if (initPosition == Vector3.zero) {
             initPosition = transform.position;
         }
         transform.position = new Vector3(initPosition.x, initPosition.y - range * Random.value, initPosition.z);
         transform.eulerAngles = Vector3.zero;
         transform.localScale = new Vector3(1, 1, 1);
 
 
     }
 
     void FixedUpdate()
     {
         velocity = new Vector2(-10, 0);
         rigidBody2d.velocity = velocity;
 
     }
         
 
     // Update is called once per frame
     void Update () {
         // Die by being out off screen
         if (transform.position.x < -13)
         {
             ObjPool.instance.cubes.putObj(gameObject);
         }
     }
 
 
 
 }
 
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graphics_Dev · Mar 06, 2016 at 07:31 PM 0
Share

Unity 5.5.3 personal doesn't exist yet: only pro users get beta versions ;)

avatar image CAH4AC · Mar 07, 2016 at 04:02 AM 0
Share

5.3.3) post updated

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My Camera rotation is lagging in completed Game 0 Answers

CAMERA FOLLOW MOVING PLAYER PROBLEM ? 0 Answers

UI Canvas Jerking Performance terrible.. 0 Answers

Jerking game when touch the screen 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges