- Home /
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.
Have you tried using Rigidbody2D.position ins$$anonymous$$d of transform.position?
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.
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?
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.
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;
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.
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.
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).
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
Follow this Question
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