Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ajkey94 · Apr 28, 2015 at 03:53 PM · 2dmovementmobilelagaccelerometer

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;
 
     }
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Apr 28, 2015 at 05:39 PM 0
Share

Is this the only object that moves? Specifically, does your camera move as well?

avatar image Ajkey94 · Apr 28, 2015 at 05:43 PM 0
Share

@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.

avatar image Santosh Patil · Apr 28, 2015 at 06:49 PM 0
Share

add a line andriod manifest in Application tab

 <application android:hardwareAccelerated="true" ...>
avatar image tanoshimi · Apr 28, 2015 at 06:52 PM 1
Share

I$$anonymous$$O, "choppiness" is most commonly caused by camera/object movement code being out-of-sync. Is your camera being moved in LateUpdate () ?

avatar image Ajkey94 · Apr 28, 2015 at 06:58 PM 0
Share

@tanoshimi it's not no, would that help with the camera follow?

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Mobile z axes movement 2 Answers

Does anyone know of a way to assign an Axis or KeyCode to a GUI Button or Texture? I'm trying to make a 2D platformer on a mobile device. As you can tell, I have no Idea what I'm doing... 1 Answer

Why isn't my joystick code working? 1 Answer

Rigid Body Movement (Mobile Issue) 3 Answers

2d or 3d for better perform on mobile devices? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges