- Home /
Everything is choppy... How can I make object movement more fluid?
Hello,
I'm having problems with making objects move fluidly through my game world.
I've toned it down to an extremely basic situation:
Setup:
5 x planes placed one after another to make a long "field"; All static
1 x cube (basic 3d shape cube)
1 x camera - child of cube
No lights, No shadows cast, no shadows received.
The following extremely simple script is attached to the cube:
void Update()
{
transform.position = Vector3.Lerp(transform.position, transform.position + transform.forward, Time.deltaTime * 5f);
}
This causes the cube to move "choppily" through the scene.
Can anyone suggest a way to make this cube move fluidly through the scene?
NOTE: the choppiness is palpable in the editor, and on my target platform (android, galaxy s4 device, 4.4.4) // using unity 5 free
Thank you.
UPDATE:
It seems that the problem is limited to Android platform builds. I tried switching to WebGL, which resulted in full fluidity in both the editor and in Chrome...
I had made a far more complex scene in 4.6 (for a different project), which did not have this choppy movement problem (on Android)... I guess I'll investigate platform specific issues and fixes...
Answer by tanoshimi · Mar 20, 2015 at 05:11 PM
That's a very peculiar movement code. If you just want to move forward at a rate of 5 units per second, try:
transform.position += transform.forward * Time.deltaTime * 5f;
I thought Lerp worked in a similar (identical) way...
Nonetheless, I tried replacing my line with yours; unfortunately it did not fix my problem... It actually feels (almost) exactly the same...
Thanks though!
Answer by ForeignGod · Mar 20, 2015 at 05:50 PM
http://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
Try implementing some dampening to your movement code. I wont write the code for you but have a link to the documentation ^^
$$anonymous$$ind of has the same effect as "Lerping" the camera's position towards the player... (like in the survival shooter demo)
Unfortunately, it didn't really help; the choppiness is still present.
When looking at the scene view, the cube does indeed seem to exhibit irregular movement...
I don't understand why my original code, or tanoshimi's, doesn't produce perfectly fluid movement... $$anonymous$$athematically, it should; especially considering this ultra-basic scene is running @ ~1000fps...
Anyways, thanks for suggestion!
Answer by UNZoOM · Mar 20, 2015 at 06:44 PM
Replace update with LateUpdate and see if it works.
"I don't understand why my original code, or tanoshimi's, doesn't produce perfectly fluid movement... Mathematically, it should " You are right , because its not the choppiness in the cube its the choppiness in the camera's perspective.
Making camera a child of the GO ( cube in your case ) is not really a good practice. Trying changing to LateUpdate , if that dosent work well then you should preferably detach the camera and script for following the movement rather.
Your answer
Follow this Question
Related Questions
2D Vector Movement,Vectorel Movement with Buttons 2 Answers
Unity Android movement 1 Answer
My vector3 lerp is not working properly 1 Answer