- Home /
2D movement stutter
Hi,
i have got some performance-trouble while duing a simple task: Moving a single Sprite / Rigidbody2d over the screen. I simply took a two sprites (one for the background and one for the moving object), placed them on the scene and wrote a script to move one of the objects. The Code i used is like this:
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour {
Rigidbody2D car;
private Vector2 speed = new Vector2(10, 0);
// Use this for initialization
void Start () {
car = this.rigidbody2D;
}
// Update is called once per frame
void FixedUpdate () {
car.MovePosition(car.position + speed * Time.deltaTime);
}
}
The Sprite is stuttering - but why? I made you a video to clarify what i am talking about / attached the project. I would be realy thankful if somebody could check what's going wrong about my projeclink textt. Thank you.
Video: http://www.file-upload.net/download-9031974/Unity-2014-06-09-15-53-09-51.rar.html Project: Attached
Kind regards Teyhouse
Hi Guys,
thanks for you response - unfortunately none of them helped. What i have tried:
Set the rigidBody to is$$anonymous$$inematic Set rigidbody.velocity directly ins$$anonymous$$d of using movePosition
This had absolutely no effect on the "stuttering"
Go to the inspector under Rigidbody2D. Select the dropdown for "Interpolate" and set to Interpolate
Done - also no effect still an ugly stuttering effects...
AddForce
Nope, i have tried AddForce (with booth Force$$anonymous$$odes), trasform.translate or setting directly the velocity - everything works or more looks the same way / using or not using time.detlatime does net cause any changes / also using LateUpdate.
If tried my project on 3 PCs and a $$anonymous$$ac - still the same result. So what i am doing wrong? I mean we are talking about a simple step: Placing two Sprites and smoothly moving one of them over the screen. This should be quite simple and smooth. I have got more than enough FPS, so it can't be kind of a performance problem.
So guys before i get crazy to make sure i do not make something wrong: Please can somebody try it himself with the latest Unity-Version 4.5.0f6? Just make a new 2D project - place a sprite and let it move from one site of the Camera to the other-site and look it you also got the stuttering-effect... if your version works pleace show it to me. This problem is getting kind of frustrating.
Thanks everybody
Answer by darthbator · Jun 11, 2014 at 01:00 AM
Fixed update runs at a fixed interval (normally 60 times a second). When you move objects in there you don't need to make them "framerate independent" by muliplying by Time.deltaTime. That might help you at the least.
Its still a good idea to maintain frame rate independence in case you decide to change the fixedTimeStep later.
Answer by Kiwasi · Jun 11, 2014 at 01:12 AM
The stuttering may occur if collisions are enabled. The physics engine will follow you instructions to move the car. However the car may end up colliding and bounce back after each frame.
Possible solutions
Set the rigidBody to isKinematic.
Set rigidbody.velocity directly instead of using movePosition
Answer by cryingwolf85 · Jun 11, 2014 at 01:17 AM
Go to the inspector under Rigidbody2D. Select the dropdown for "Interpolate" and set to Interpolate.
Answer by Miziziziz · Jun 11, 2014 at 01:34 AM
if you're going to use physics, maybe use AddForce rather than Vectors for movement