Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
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.

Show more comments

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.

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

Continously correct rotation 3 Answers

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


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