• 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 Daruom · Apr 14, 2015 at 11:30 AM · movementsmoothjitter

Is't impossible to move an object without jittering

Hi,

I try to move an object but it seems impossible to have a jitter-free movement.

I already published the game : https://play.google.com/store/apps/details?id=com.MDevApp.JumpingBall In this version, i used this code ( Rigidbody2D + is Kinematic On)

 public Vector2 speed = new Vector2(0,-5);
 public float range =1.7f;
  
 void Start () {
  
         GetComponent<Rigidbody2D> ().velocity = speed;
         transform.position = new Vector3 (transform.position.x - range * Random.value, transform.position.y,transform.position.z);
       }

 

I also tried : - Translate ( without Rigidbody2D) - Add force ( with Rigidbody2D + is Kinematic Off) - Character controller

Each time i tried with Update(),FixedUpdate() and switching between Time.deltaTime, Time.FixedeltaTime and Time.smoothDeltaTime, Turning VSync On/Off, changing FixedTimestep to differents values (0.0166 for example),Interpolate/Extrapolate. I really tried everything i found on forums.

I tested the game on many devices and for some of them the movement looked smooth but for others the jittering was obvious.

So i really want to know, is't impossible to move an object without jittering or am i missing something.

Thanks.

Comment
Add comment · Show 14
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 Daruom · Apr 13, 2015 at 10:35 AM 0
Share

Any help would be appreciated

avatar image cobertos · Apr 14, 2015 at 01:52 PM 0
Share

Have you tried using Rigidbody2D.position ins$$anonymous$$d of transform.position?

avatar image Daruom · Apr 14, 2015 at 06:52 PM 0
Share

Actually i did, with this code :

     public Vector2 velocity = new Vector2 (0, -5.0f);
     public float range = 1.7f;
     private Transform tr;
     public Rigidbody2D rb2D;
 
     void Awake ()
     {
         // Store references to save CPU time.
         tr = GetComponent <Transform> ();
         rb2D = GetComponent <Rigidbody2D> ();
     }
     
     void Start ()
     {
         // Set X position to random range.
         float randomX = Random.Range (tr.position.x - range, tr.position.x + range);
         
         tr.position = new Vector3 (randomX, tr.position.y, 0);
     }
     
     void FixedUpdate ()
     {
 
         rb2D.$$anonymous$$ovePosition (rb2D.position + velocity * Time.deltaTime);
     } 

Same problem : jitters on many devices.

avatar image cobertos · Apr 14, 2015 at 06:56 PM 0
Share

What specific devices are you talking about? Is this some corner case device or if I run this on PC should I have the same problem?

avatar image Daruom · Apr 14, 2015 at 07:19 PM 0
Share

By Devices i mean android device. For example i runed the previous code on Samsung Ace 4 and i looked really smooth but it looked really bad ( obvious jitters) on Samsung Galaxy S5. Actually i noticed that the more powerfull and bigger the screen is, the more jitters are obvious.

avatar image cobertos · Apr 14, 2015 at 07:35 PM 0
Share

Try this... Considering I can't tell whether you want your Rigidbody to be kinematic or not because I dont know your game well enough.

If it is kinematic (you have to drive the position manually): Use FixedUpdate, default FixedTimestep, Time.deltaTime, (VSync shouldn't matter), and use rb2D.$$anonymous$$ovePostion(...) like you have.

If it's not kinematic (let the physics engine take care of it): Use FixedUpdate, default FixedTimestep, Time.deltaTime, (VSync shouldn't matter), and use rb2D.AddForce(..., Force$$anonymous$$ode.VelocityChange) to change the velocity ins$$anonymous$$d of directly modifying the position. You could also just set the velocity if you need to versus changing it (which just adds to current velocity). The code you're showing above literally just does the work the physics engine does normally but does it in a $$anonymous$$onoBehaviour.

If this doesn't solve it, it sounds like a device problem or a problem in some other part of your code. I'm also a little weary of the tr.position in Start. Even though it probably isn't much, you should change that to use rb2D.$$anonymous$$ovePosition so the physics engine is properly alerted of the position changing.

avatar image tanoshimi · Apr 14, 2015 at 08:08 PM 0
Share

Is the rigidbody the only thing moving in the scene? Or, specifically, is the camera moving as well? In my experience, most "jittering" occurs due to mismatched movement of the camera relative to other moving objects.

avatar image Daruom · Apr 14, 2015 at 09:28 PM 0
Share

@Coburn37 I'm using $$anonymous$$inematic Rigidbody and have already set up everything like you said (also use Interpolate). I don't think it's a device problem because i tested on many devices, it's just the result how change from one device to another and like i said in my first post i've already published the game so if you can test it (if you have the time of course) youll'se the jitters and it give you a better idea of my problem.

I also tried to use Not kinematic Rigidbody with AddForce but i didn't manage to get the right speed or behavior ( probably because i didn't work with AddForce with it before ). Can you give me an idea of what the code will look if i want to use AddForce with the same speed and the same behavior ( i mean to have a constant speed).

@tanoshimi Actually it's a gameobject with rigibodies attached to the two childrens and i use InvokeRepeat so many clone of this gameobject exist in the same time ( I destroy them after a short time) but no script attached on the camera, the player and the obstacles are the only things moving the entire game.

avatar image tanoshimi · Apr 14, 2015 at 09:45 PM 0
Share

You destroy and instantiate objects? Are you sure that your jittering is not caused by CPU spikes as a result? What does your profiler look like?

avatar image Daruom · Apr 14, 2015 at 10:08 PM 0
Share

It could be that but i can't be sur and i don't have Unity pro to use a profiler :/

avatar image Daruom · Apr 15, 2015 at 03:28 PM 0
Share

I also tried pooling objects. Same result always the jitters.

avatar image cobertos · Apr 15, 2015 at 03:44 PM 0
Share

Just tested it on a Nexus 5, no problems here, unless there's some really small jitters that I'm having trouble seeing. It's pretty smooth on my end.

avatar image Daruom · Apr 15, 2015 at 04:11 PM 0
Share

@Coburn37 You didn't see any jitters at all ? that got me even more confused because i didn't update the code yet and in this version i'm still using Velocity + transform.position ... I'm going to upgrade to Unity5, maybe that well improve things. Thank you for the test, i guess the result depend on the device (or i'm crazy). I let you know if i found something.

avatar image cobertos · Apr 15, 2015 at 07:02 PM 0
Share

Yeah, I'm not really sure why. I assume you're not crazy so...

I don't suggest switching over to non-kinematic. If you want you can but you'd have to apply a physics material with no friction on your ball and friction blend to multiply (if it's actually colliding with anything) and then what you would do is just set the .velocity member on the Rigidbody whenever you want to set it or use AddForce with Force$$anonymous$$ode.VelocityChange whenever you want to add or subtract from it. Then the Physics engine would actually take care of applying it.

I don't think I can be of further help as everything else looks normal to me and this seems to be the correct way of doing it if you're doing it with a kinematic rigidbody.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ironblock · Apr 14, 2015 at 11:39 AM

you shuild use time.delta time to maka a smoth transision float MovementSpeed = 2;

 transform.position += transform.forward * Time.deltaTime * MovementSpeed;
Comment
Add comment · Show 1 · 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
avatar image Daruom · Apr 14, 2015 at 12:39 PM 0
Share

I tried your way :

     float $$anonymous$$ovementSpeed = 2;
     public Vector2 speed = new Vector2(0,-4.8f);
 
 
     void Start()
     {
         GetComponent<Rigidbody2D> ().velocity = speed;
     }
     
     void FixedUpdate()
     {
 
         transform.position += transform.forward * Time.deltaTime * $$anonymous$$ovementSpeed;
     }

VSync Off / Is $$anonymous$$inematic

But still jittering on devices. Actually i noticed that the more powerfull and bigger the screen is, the more jitters are obvious.

avatar image
0

Answer by spalmer · Apr 15, 2015 at 06:24 PM

Time.deltaTime is wrong for FixedUpdate, should be Time.fixedDeltaTime there. The rigidBody definitely needs set to kinematic if you're messing with position directly like this. One of the myriad problems doing motion this way is the physics engine must then extrapolate the positions to obtain a velocity; if it doesn't do this or fails somehow it won't be able to reconstruct interpolated positions for the intermediate rendered frames properly. Another is that you're bypassing intermediate space for collision, including any continuous collision detection it may provide. You're not supposed to teleport objects in a physics simulation. You should just set a velocity on the rigidBody and let the physics engine manage the position like it was designed to do.

Comment
Add comment · Show 2 · 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
avatar image Daruom · Apr 15, 2015 at 06:39 PM 0
Share

I was thinking that Time.deltaTime will return Time.FixedDeltaTime inside of FixedUpdate. Anyway this lines of code didn't give me a good result, $$anonymous$$ovePosition reduce the jitters but don't remove them completly(looks fine on the editor but different story on devices).

avatar image cobertos · Apr 15, 2015 at 06:58 PM 0
Share

No, he/she can use time.DeltaTime. http://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html

The docs say: "For reading the delta time it is recommended to use Time.deltaTime ins$$anonymous$$d because it automatically returns the right delta time if you are inside a FixedUpdate function or Update function."

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

6 People are following this question.

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

Related Questions

Smooth Camera/Object Movement 1 Answer

Jittery FPS Camera when moving 3 Answers

[Solved]NetWork not smooth 1 Answer

How do I make Rigidbody2D movement smoother? 0 Answers

How to incorporate Time.deltaTime into existing script 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