- Home /
Mobile Movement Choppy in 2d endless runner
This is currently how I am moving my character, which is along the y axis while also being able to move left and right using a phones accelerometer. It seems to move smoothly on the unity player but when I build it to my nexus 6 it moves fairly choppy every few seconds. I've done a lot of research through other questions but I've still come up with nothing. I tried to limit the FPS, change V sync options but I can't find an efficient way to move the character endlessly.
Note: It ran pretty well on my Note 2 (my theory is that the nexus is running at way higher FPS causing performance issues.
void Update()
{
if (canMove)
{
transform.Translate(Vector3.up * Time.deltaTime * speed);
Vector3 dirx = Vector3.zero;
if (drunk)
{
dirx.x = -Input.acceleration.x;
}
else
{
dirx.x = Input.acceleration.x;
}
if (dirx.sqrMagnitude > 1)
dirx.Normalize();
dirx *= Time.deltaTime;
transform.Translate(dirx * leftRightSpeed);
}
// Get current position
Vector3 pos = transform.position;
// Horizontal contraint
if (pos.x < minX) pos.x = minX;
if (pos.x > maxX) pos.x = maxX;
// Update position
transform.position = pos;
}
Is this the only object that moves? Specifically, does your camera move as well?
@tanoshimi The camera is following the character by using the characters transforms and assigning it to the camera within a script. The camera is only following on the y axis.
add a line andriod manifest in Application tab
<application android:hardwareAccelerated="true" ...>
I$$anonymous$$O, "choppiness" is most commonly caused by camera/object movement code being out-of-sync. Is your camera being moved in LateUpdate () ?
@tanoshimi it's not no, would that help with the camera follow?
Your answer
Follow this Question
Related Questions
Mobile z axes movement 2 Answers
Why isn't my joystick code working? 1 Answer
Rigid Body Movement (Mobile Issue) 3 Answers