- Home /
Smooth movement of simple GameObject on Android
Hi, I am making a simple game like Curve Fever. I have simple scene with few GameObjects and one dot which is moving linearly. The problem is that the movement is not smooth - only on very powerful devices which is weird because there is not much in the scene. On my phone i can see little lags, background is "jumping". I tried many things:
using Translate/MoveTowards/Lerp in different combinations
using Update/FixedUpdate/LateUpdate also with decreasing time between FixedUpdate calls
changing quality settings like Vsync
removing everything from scene (like canvas), only moving object was active
even I was testing with animation changing the position of object
So do you have any ideas what is wrong? Game was tested on many devices and the problem is repeating.
Object has Rigibody2D (kinematic) and circle collider.
Edit: Current code:
void FixedUpdate()
{
transform.Translate(Vector2.up * speed * Time.fixedDeltaTime, Space.Self);
if (direction != 0)
{
rotationSpeed = 2 * speed * radius;
transform.Rotate(Vector3.forward * -direction * rotationSpeed * Time.fixedDeltaTime);
}
if (isAccelerating)
{
speed += speedIncrease * Time.fixedDeltaTime;
EndlessModeGameManager.instance.SetTimerValue(speed);
}
}
But as I said i tried many other versions and still only powerfull phones can handle it
Check if you have 60 fps.
Post code, maybe you implement something wrong. (Remember: Time.fixedDeltaTime is for FixedUpdate and Time.deltaTime you using in Updates and LateUpdates)
If game object contains rigidbody set interpolation on.
@$$anonymous$$asterio 1. Stable 45fps on my phone 2. I pasted the code 3. GameObject hast interpolation on now but still it is not perfect smooth movement ;/
It should be in Update. Next check profiler maybe you have some scripts what use a lot of cpu. Camera moves should be in LateUpdate.
Restore FicedUpdate refresh time to default 0.2
But I need to use FixedUpdate because game will be using multiplayer and i want to have equal steps between updates Also i checked profiler and founf that Graphics.graphics.presentandsync is using a lot of CPU. Now i am searching what is wrong with rendering(?)
@fazol Can you post the camera code too , You need to sync both to get smooth movement
Camera is attached to gameObject. There isn't any script to move camera
Answer by lgarczyn · Mar 14, 2017 at 06:10 PM
Three solutions:
Try using Update() and Time.deltaTime,
Increase or decrease the fixed update interval to a multiple of your ideal framerate
Activate "interpolate" on your rigidbody2d (if you don't have one, add it, remove gravity, set as kinematic)