Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sid.10 · Dec 21, 2015 at 05:39 PM · c#androidcameramovementscript.

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction?

While controlling a sphere ball through accelerometer, while turning left or right I want both the object and the camera to turn towards that direction. Current State : ball moving in that direction and camera is only looking at the ball, not in the direction in which it is moving. I have been trying to look solutions to this problem for the past several days; Any help would be much appreciated. :)

Ball Controller:

 curAc = Vector3.Lerp(curAc, Input.acceleration-zeroAc, Time.deltaTime/smooth);
                 GetAxisV = Mathf.Clamp(curAc.y * sensV, -1, 1);
                 GetAxisH = Mathf.Clamp(curAc.x * sensH, -1, 1);
 
                 Vector3 movement = new Vector3 (GetAxisH, 0.0f, GetAxisV);
 
                 GetComponent<Rigidbody>().AddTorque(movement * speedAc);

Camera Controller:

 void Start()
     {
         playerOffset = transform.position - player.transform.position;
     }
 
     
     void LateUpdate()
     {
         transform.position = player.transform.position + playerOffset;
     }


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Sid.10 · Dec 23, 2015 at 04:27 PM

I'm the OP, but I solved the problem, atleast to my satisfaction. Creating an empty game object and making the ball and the camera child of it worked for me. The hierarchy :

  • Empty Game Object(Container)(Parent)

  • Ball(Child 1)

  • Camera(Child 2)

Then, apply the movement controller script on that empty game object. Hope this helps to someone in the future. Cheers :)

Comment
Add comment · Share
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Disable Camera Movement,Stop camera movement 0 Answers

Regarding transform.position in the roll a ball tutorial 1 Answer

Why does my app function correctly in Unity Remote but not compiled as an app? 0 Answers

Standard asset question 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