• 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 /
avatar image
0
Question by fazol · Mar 14, 2017 at 01:58 PM · androidunity 5movementperformancelags

Smooth movement of simple GameObject on Android

Hi, I am making a simple game like Curve Fever. I have simple scene with few GameObjects and one dot which is moving linearly. The problem is that the movement is not smooth - only on very powerful devices which is weird because there is not much in the scene. On my phone i can see little lags, background is "jumping". I tried many things:

  • using Translate/MoveTowards/Lerp in different combinations

  • using Update/FixedUpdate/LateUpdate also with decreasing time between FixedUpdate calls

  • changing quality settings like Vsync

  • removing everything from scene (like canvas), only moving object was active

  • even I was testing with animation changing the position of object

So do you have any ideas what is wrong? Game was tested on many devices and the problem is repeating.

Object has Rigibody2D (kinematic) and circle collider.

Edit: Current code:

 void FixedUpdate()
     {
         transform.Translate(Vector2.up * speed * Time.fixedDeltaTime, Space.Self);
 
         if (direction != 0)
         {
             rotationSpeed = 2 * speed * radius;
             transform.Rotate(Vector3.forward * -direction * rotationSpeed * Time.fixedDeltaTime);
         }
       
         if (isAccelerating)
         {
             speed += speedIncrease * Time.fixedDeltaTime;
             EndlessModeGameManager.instance.SetTimerValue(speed);
         }
     }

But as I said i tried many other versions and still only powerfull phones can handle it

Comment
Add comment · Show 12
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 TreyH · Mar 14, 2017 at 02:00 PM 0
Share

link code?

avatar image Masterio · Mar 14, 2017 at 02:18 PM 0
Share
  1. Check if you have 60 fps.

  2. Post code, maybe you implement something wrong. (Remember: Time.fixedDeltaTime is for FixedUpdate and Time.deltaTime you using in Updates and LateUpdates)

  3. If game object contains rigidbody set interpolation on.

avatar image fazol · Mar 14, 2017 at 03:18 PM 0
Share

@$$anonymous$$asterio 1. Stable 45fps on my phone 2. I pasted the code 3. GameObject hast interpolation on now but still it is not perfect smooth movement ;/

avatar image Masterio fazol · Mar 15, 2017 at 08:42 AM 1
Share

It should be in Update. Next check profiler maybe you have some scripts what use a lot of cpu. Camera moves should be in LateUpdate.

Restore FicedUpdate refresh time to default 0.2

Show more comments
avatar image Mughees_Mehdi · Mar 15, 2017 at 07:33 AM 0
Share

@fazol Can you post the camera code too , You need to sync both to get smooth movement

avatar image fazol · Mar 15, 2017 at 09:27 AM 0
Share

Camera is attached to gameObject. There isn't any script to move camera

avatar image TreyH · Mar 15, 2017 at 06:10 PM 0
Share

And the profiler has told you that this function is eating up your computing time?

avatar image fazol · Mar 15, 2017 at 06:27 PM 0
Share

Yes, but still i don't know what is wrong. I found only that it is something with rendering

avatar image TreyH · Mar 15, 2017 at 06:29 PM 0
Share

Could you post the code for Endless$$anonymous$$odeGame$$anonymous$$anager.SetTimerValue() ?

avatar image TreyH · Mar 15, 2017 at 06:31 PM 0
Share

Have you tried exchanging transform.Translate and transform.Rotate with the rigidbody equivalents?

avatar image fazol · Mar 15, 2017 at 06:36 PM 0
Share

JUST FOUND IT! It was image on canvas that i was using to fade in/out to show game over screen etc. After changing its alpha to 0 it was still active and that was the problem. After deactivating this object i have stable 60 fps on my phone. $$anonymous$$orrow i will test it on other devices but i think i found the sollution ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lgarczyn · Mar 14, 2017 at 06:10 PM

Three solutions:

  • Try using Update() and Time.deltaTime,

  • Increase or decrease the fixed update interval to a multiple of your ideal framerate

  • Activate "interpolate" on your rigidbody2d (if you don't have one, add it, remove gravity, set as kinematic)

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Bad performance on certain android devices 1 Answer

Android performance hit on changing Button.Interactable 1 Answer

Is it possible to get the forward and backward movement of android device 1 Answer

The bullet doesn't move correctly 1 Answer

What is most efficient way to render output of multiple cameras 1 Answer


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