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 DevMerlin · Jun 03, 2013 at 04:32 AM · androidcameratranslate

How can I move a camera on Android with a virtual button press - smoothly?

I am writing a 2D sidescrolling game for Android and coming from primarily PC development. Normally I'm used to using .translate() but that doesn't seem to move all that smoothly on my test machine - a Galaxy S3. After reading suggested tips, people seem to recommend using transform.position +=. I have two buttons set up to emulate a axis, supplying 1, -1 and 0 values for right, left and no detection.

What is the best way to ensure the camera moves smoothly on a horizontal plane, as long as these buttons are pressed?

Comment
Add comment · Show 3
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 DevMerlin · Jun 03, 2013 at 07:11 AM 0
Share

Any thoughts? I'm curious to see what the options are.

avatar image Jamora · Jun 03, 2013 at 07:41 AM 0
Share

How optimized is your game to a mobile device? A lot of draw calls, for instance might cause lag.

avatar image DevMerlin · Jun 03, 2013 at 07:58 AM 0
Share

At the moment it uses 29, with a maximum allowed of 50. Both meshes and textures are optimized for mobile. I've got movement working semi-smooth but now running into control problems, related to the emulated axis. I'm using NGUI. Whenever I press and hold a button, it should keep moving. However.. it moves, and stops, then refuses to move until the axis buttons are pressed again:

     public void axisUpdate(string dir)
     {
         switch(dir)
         {
             case "left":
                 horizontalControl = -1;
                 break;
             case "right":
                 horizontalControl = 1;
                 break;
             case "release":
                 horizontalControl = 0;
             break;
         }
         
         if (horizontalControl != 0)
         {
             StartCoroutine("moveCamera");
         }
     }
     
     IEnumerator moveCamera()
     {
         //moving = true;
         
         float i = 0;
         
         Vector3 camPosistion = transform.position;
         
         Vector3 movePosistion = new Vector3(horizontalControl, 0, 0);
             
         Vector3 destination = camPosistion + movePosistion;
         
         Debug.Log(destination);
         
         while (i < 1)
         {
             i += Time.deltaTime * 5;
 
             transform.position = Vector3.Lerp(camPosistion, destination, i);
             yield return 0;
         }
         
         //moving = false;
     }

EDIT: 29 is highest possible currently. The normal is barely at 20.

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android Cardboard - Fake UI Overlay 0 Answers

Android Unity ARCore camera access 0 Answers

OnRenderImage in one of the two cameras, Android showing only post processed camera. 1 Answer

Second Camera Tearing on Android 1 Answer

my camera show an extremely weird aspect [android] 0 Answers


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